如何使用PHP中的代码复制网页的文本

Sad*_*egh 6 php

我想将页面的文本复制到PHP变量中.我使用file_get_contents(...)方法,但它不适用于我的地址,例如我的地址是:

http://www.bankmellat.ir/3/Default/94/1/Default/2/875/1/201.aspx?itemid=201

但此代码不显示此页面的文本:

$filename='http://www.bankmellat.ir/3/Default/94/1/Default/2/875/1/201.aspx?itemid=201';
$homepage =  file_get_contents($filename , false);
echo ($homepage);
Run Code Online (Sandbox Code Playgroud)

cod*_*nia 0

大多数托管服务现在都会阻止furl_open允许您file_get_contents()从外部 URL 加载数据的参数。

使用此代码:

<?php
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";

// INIT CURL
$ch = curl_init();

//init curl 
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL, 'http://www.bankmellat.ir/3/Default/94/1/Default/2/875/1/201.aspx?itemid=201');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);

// common name and also verify that it matches the hostname provided)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

// Optional: Return the result instead of printing it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

$store = curl_exec ($ch);
echo $store;

// CLOSE CURL
curl_close ($ch);
?>
Run Code Online (Sandbox Code Playgroud)

享受!!