This is a discussion on Multiple String replace within the PHP General forums, part of the PHP Programming Forums category; Hi, I'm looking for a method to replace on submit keywords that a user inputs into a memo fieldtype. ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
On 8 May, 00:10, Gavin <GJPeac...@gmail.com> wrote:
> 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. Anyone know of a pre-written script or something similar in php? |
![]() |
| Thread Tools | |
| Display Modes | |
|
|