Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic html code capture

Status
Not open for further replies.

erikkk

Programmer
Jun 25, 2001
12
0
0
IT
Does anybody knows if there is a php script or a php function that allows to capture the html code from an external webpage inserting the url as parameter? A sort of: view source - select all - copy - paste.
Thanks!
P.S. don't warry it's not a code theft, I just need to bring back news from a site to another one as fast as possible.
 
Thank you, but it wasn't really helpful because I need to obtain a new page where I can edit the html code and not simply a copy of the page that I capture.
Thanks.
 
The readfile function simply outputs the file, rather than allowing you to set a string variable for that file's contents. In fact, the return value of the function is the number of bytes read, so $output in Anikin's example above would be something like 4556, or whatever, but the rest of the contents of the page would echo out anyway, since that is what readfile does (
What you need is to use one of the other PHP file access functions. Unfortunately, there is no single function in PHP that let's you just set a variable equal to a remote file, but the file() ( command is the closest. It actually returns an array for each line of the file, which can be a very useful thing in itself. And to get a regular string variable out of it, you just need to use a join() ( You can nest these functions for nice compact code.

So, if you want to take a user's input, grab the HTML page that the user requests, place it in a <textarea> box for editing, you can do something like:
Code:
$output = join(&quot;&quot;,file($users_input_url));
//join the array with a null string
fix_output = htmlentities($output);
//escape HTML tags that will 'break out' of
//the textarea tagset

echo &quot;<textarea>$fix_output</textarea>;
//... finish with the rest of your form //to submit user's edited version
-------------------------------------------

&quot;Calculus is just the meaningless manipulation of higher symbols&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-unknown F student
 
Sorry, the form mangled my code example. Here it is again:
Code:
$output = join(&quot;&quot;,file($users_input_url));
//join the array with a null string
$fix_output = htmlentities($output);
//escape HTML tags that will 'break out' of
//the textarea tagset

echo &quot;<textarea>$fix_output</textarea>;
//... finish with the rest of your form 
//to submit user's edited version  -------------------------------------------

&quot;Calculus is just the meaningless manipulation of higher symbols&quot;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[i]-unknown F student[/i]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top