Arjun Bajaj
Arjun Bajaj

Reputation: 1972

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? or is there any other option?

Upvotes: 1

Views: 1051

Answers (3)

ngduc
ngduc

Reputation: 1413

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

Upvotes: 1

bensiu
bensiu

Reputation: 25594

by using file_get_contents()

Upvotes: 2

Peter Bailey
Peter Bailey

Reputation: 105906

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

Upvotes: 2

Related Questions