Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 'Unknown Modifier' with preg_replace

    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 Code:
    <?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

    ?>

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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'],'/')
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)

  • #3
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wow your right, it works a dream

    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 )

    Jonathan


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •