Page 1 of 1

append or replace

Posted: Sun May 06, 2007 3:25 pm
by php246
Hi,

We parse our HTML as PHP.

All of internal links within any HTML page finish with “.html”.

We would like to insert a variable at the end of each internal link. That means we would like to either replace “.html” with “.html?variable” or to simply append “?variable” to “.html”.

We played extensively with str_replace and searched the Web and forums a lot. Whatever we do it works fine except that it does not go down the code and does the replacement. For example:

Code: Select all

<php?
$old = “.html”;
$new = “.html?variable”;
$replace = str_replace($old, $new, $replace);
echo $replace;
?>
Echo shows the desired result. Now, how do we replace each instance of $old with $new in the whole HTML code, between the body tags?

Thanks.

Posted: Mon May 07, 2007 3:11 pm
by andym01480
From the way you have phrased the question, it seems you are wanting to statically replace all instances of ".html" with ".html?variable". A text editor's "replace" function would do that! Open all the relevant files and do a global replace.

If you are wanting to dynamically replace them with different variables depending on what is happening in the script, you need to rephrase the question.