Multiple String replace
Hi,
I'm looking for a method to replace on submit keywords that a user
inputs into a memo fieldtype. In essence, something similar to the
Javascript Kontera system, but using php and processing once on the
forms submission.
I would have a table of keywords and a coinciding url. I want the url
to be wrapped around the keyword when the data get's stored in the
database.
one two three four five
becomes
one <a hrf=>two</> three <a hrf=>four</> five
I've so far came up with this:
$sql = "select * from table;";
$result = mysql_query($sql);
$user_input = $_POST[user_input];
while($row = mysql_fetch_assoc($result)) {
$replacement = $row[replacement];
$to_replace = '<a href="'. $row[url].'"> '.$replacement .'</a>';
$user_input = str_replace($replacement, $to_replace, $user_input);
}
Can anyone see any issues with this, or a better way to do it? I
appologise if my code is not good, i'm a bit of a newbie. I've tried
searching but couldn't see any other posts like this.
Thanks for your help.
|