PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Multiple String replace
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Multiple String replace

Réponse
 
LinkBack Outils de la discussion
Vieux 08/05/2008, 00h10   #1
Gavin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 .
  Réponse avec citation
Vieux 08/05/2008, 22h50   #2
Gavin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 .


Anyone know of a pre-written script or something similar in php?
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 15h54.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,07317 seconds with 10 queries