开发者

How to get text from a webpage outside my server through php?

I first send a term to a webpage outside my site. Then that page returns only text. I want to take that text and process it? So I'll have to get that text on my server for that right? So how can i do it开发者_如何学C? or is there any other option?


by using file_get_contents()


Use cURL or file_get_contents() if your server has the URL wrappers enabled.


Below is the code to read remote file using PHP

if ($fp = fopen('http://www.google.com/', 'r')) {
   $content = '';
   while ($line = fread($fp, 1024)) {
      $content .= $line;
   }
} else {
   // an error occured when trying to open the specified url 
}

Make sure you have 'allow_url_fopen' set to 1 in your php.ini

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜