append or replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php246
Forum Newbie
Posts: 3
Joined: Sat Apr 28, 2007 12:13 am

append or replace

Post 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.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post 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.
Post Reply