str_replace problem

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
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

str_replace problem

Post by someguyhere »

The line of code below is supposed to take a paragraph and replace a particular word in that paragraph with a hyperlinked copy of that word. Everything works except that the url in the link is blank. It is defined earlier in the document and works elsewhere, just not here, so I assume I must have the syntax wrong? What am I missing?

Code: Select all

$par1=str_replace("example","<a href='$url'>$input1[$rand_key1]</a>", $par1);
 
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: str_replace problem

Post by califdon »

Try

Code: Select all

$par1=str_replace("example","<a href='$url'>" . $input1[$rand_key1] . "</a>", $par1);
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: str_replace problem

Post by someguyhere »

No, the url is still blank
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: str_replace problem

Post by someguyhere »

I got it to work.
Post Reply