Rackover Rackover - 4 months ago 11
PHP Question

PHP Get content of another php page

I've got a webpage that display this : http://i.imgur.com/QUkMoiC.jpg
Just plain text. And I need to include this in another php webpage, like

$string = include('http://77.144.233.158:4032/currentsong?sid=1');
echo $string;


so this can return "King crimson - Moonchild - Lyrics".
but this doesn't work.

How can I do ?

Answer

Include will evaluate what's inside the specified file (And run it as PHP). For example, if you had:

$str = 'King crimson - Moonchild - Lyrics';

You could include it, and then echo $str to get what you are looking for.

I think what you're looking for is file_get_contents():

$string = file_get_contents('http://77.144.233.158:4032/currentsong?sid=1');
echo $string;

From the docs:

file_get_contents() is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance.