Jump to content

Change content in readfile() before output


windowsdan

Recommended Posts

Hi there,

 

Trying to change content in an HTML link before it is output using readfile?

 

Example:

<?php
//Get link
$link = $_POST['link'];

//Posted data may contain spaces that need to be + symbol -- then added to end of link
$link = strtr($link, array(
''=> '+',
));

HERE I NEED TO CHANGE THE OUTPUT SO THE HTML REPLACES CERTAIN ELEMENTS WITH SOMETHING ELSE

//Output the HTML page that is the result
readfile('http://www.domain.com/result?='.$link."");

?>

Any help would be amazing? :)

use urlencode when forming the link

 

Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.

Use urldecode when retrieving the link

Ok cool. The file_get_contents works for what I want but the next bit is quite a bit harder ... 

 

I then need to make 'href=' links within the file contents make a post of a variable to another page. But there is more than one 'href' links in the file contents.

 

So Example:

<?php
//get post data
$link = $_POST['link'];
//change spaces for + symbols
$link = strtr($link, array(' ' => '+',));
//pull the contents of the file at URL location
$html = file_get_contents('http://domain.com/results?search='.$link."");
//change required contents before output
$html = strtr($html, array('ORIGINAL' => 'REPLACED',));
//output contents
echo $html;

?>

But the ORIGINAL and REPLACED bit I need to replace all the 'href' links so that they post a string to another PHP page, for grabbing with POST later, when clicked on. Instead of just hot linking to the original link.

 

Hope this make sense :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.