...

View Full Version : 'Unknown Modifier' with preg_replace



jonno946
01-11-2004, 12:18 PM
Hi there,

I am in the process of getting my smilies script working.

I have a table in my database containing both the original smilie (e.g. :P), and what to change it to (e.g. <img src=cheeky.gif>).

I do however, want it to be case insensitive (e.g :P and :p would bring up the same smilie face).

I have checked out the PHP manual and came up with the following, however i am getting unknown modifier errors.

Can anyone spot what could be wrong?

Any help would be much appreciated - its been bugging me so much!

Thanks!

Jonathan

php:



<?php

$str_rep = "SELECT * FROM smilies";

$str_rep_result = mysql_query($str_rep, $db) or die ("Couldn't execute query");

$output = nl2br(htmlentities($post_vars[message]));

$search=$replace=array();

while ($str_rep_row = mysql_fetch_array($str_rep_result)) {

$search[] = '/'.preg_quote($str_rep_row['original']).'/i';

$replace[] = $str_rep_row['change_to'];

}

$output = preg_replace($search, $replace, $output);

echo $output;

?>

ReadMe.txt
01-11-2004, 02:38 PM
i can onnly assume that you have an unescaped / inside your database for the search string, you need to add the optional second parameter of delimiter (str) to the preg_quote function, eg:

preg_quote($str_rep_row['original'],'/')

jonno946
01-11-2004, 02:48 PM
wow your right, it works a dream :D

Yes i do have some smilies with a / in them, that could have been the problem i take it?

thanks thanks thanks (and thanks again :D)

Jonathan



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum