Multiple String replace

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. ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 5 Days Ago
Gavin
 
Posts: n/a
Default 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.
Reply With Quote
  #2 (permalink)  
Old 4 Days Ago
Gavin
 
Posts: n/a
Default Re: Multiple String replace

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?
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:56 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0