PTS Posted April 3, 2007 Share Posted April 3, 2007 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. Quote Link to comment Share on other sites More sharing options...
joquius Posted April 3, 2007 Share Posted April 3, 2007 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); Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted April 3, 2007 Share Posted April 3, 2007 <?php $sql = mysql_query("SELECT * FROM users_tbl WHERE condition"); while ($row = mysql_fetch_assoc($sql)){ str_replace('$row['name']', '<a href="/profile.php?playerid={$row['ID']}">{$row['name']}</a>', $fullstory); } ?> Quote Link to comment Share on other sites More sharing options...
PTS Posted April 3, 2007 Author Share Posted April 3, 2007 Thank you sir! I figured it out but your way is 10x easier than what I came up with! It worked like a charm. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.