Jump to content

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? :)

Edited by windowsdan

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

Edited by Ch0cu3r

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 :)

Edited by windowsdan
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.