Jump to content

Multiple Replacements in String


PTS

Recommended Posts

I'm trying to figure how to make multiple replacements in a string before echoing the string out.

 

str_replace('Chris Drury', '<a href="/profile.php?playerid=23">Chris Drury</a>', $fullstory);

 

The above code does what I need it to do but just for one player. I want to find a way to make it happen for about 30 players.

 

Is there a way to do this in PHP?

 

Thanks in advance for any advice or direction.

Link to comment
Share on other sites

Well, I would advise using a regular expression to match a name, or, if you have the list before hand, simply make an array:

$array = ("/Player1/","/Player2/","/PlayerN/");

and then

$text = preg_replace ($array, "<a href=\"\">$1</a>", $text);

 

Link to comment
Share on other sites

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.