Str replace only full words??
Posted: Fri May 21, 2004 2:30 am
hi,
i have made a script.
but the thing is that when he replaces words from a database, he also replaces b.v. when the word AI is in the database then in the word Wait he replaces ai automaticly.
he replaces words that are in the database with hyperlink words (and if you click that then you get info about that word).
i only want to let php replace words IF it is a standalone word so:
how can i do that?
see the script underneath here:
replace.php
okay some variables:
bericht = message
vervang = replace
verander = change
Please help me!
i have made a script.
but the thing is that when he replaces words from a database, he also replaces b.v. when the word AI is in the database then in the word Wait he replaces ai automaticly.
he replaces words that are in the database with hyperlink words (and if you click that then you get info about that word).
i only want to let php replace words IF it is a standalone word so:
Code: Select all
the word Replace?
____________________
AI YES
Wait Nosee the script underneath here:
replace.php
Code: Select all
<?
// the hyperlink function
function vervang ($bericht)
{
$breezah = FALSE;
$bericht = nl2br(htmlspecialchars(stripslashes($bericht)));
// Get info from database and replace words mysql_connect('*****','******','*******'); mysql_select_db('******');
$resultaat=mysql_query("SELECT * FROM lijst;");
while(list($id,$catid,$naam,$info)=mysql_fetch_row
($resultaat)){
$bericht = str_replace("$naam","<a hRef='detail.php?id=$id'>$naam</a>",$bericht); $naam2 = strtolower($naam);
$bericht = str_replace("$naam2","<a hRef='detail.php?id=$id'>$naam</a>",$bericht);
}
// Return the hyperlink and the text
return $bericht;
}
echo vervang($_POST[bericht]);
// Form to input text...
?>
<FORM METHOD=POST ACTION="vervang.php">
<B>Verander deze tekst in een vervang TeKsT:</B><br>
<TEXTAREA NAME="bericht" ROWS="10" COLS="50"></TEXTAREA><br>
<INPUT TYPE="submit" value="verander!" name="submit">
</FORM>
<?
?>bericht = message
vervang = replace
verander = change
Please help me!