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

Thread: error massage

  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts

    error massage

    Hi;
    Could anyone debug for me, please.

    Warning: preg_replace() [function.preg-replace]: Unknown modifier 'a' in index.php on line 6

    my code as following;


    PHP Code:
    <?php     //line 1

    $str='   test      &     me   ';
    $p='^[^a-z]+$';
    $r='_';
    $str=preg_replace($p$r$str);   // here is line 6
    echo $str;

    ?>

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    When you use preg_replace you need to start with a character and end with the same character and put any modifiers after the end character.

    eg.
    PHP Code:
    preg_replace('#hi#''hello'$text); // Replaces hi with hello using # as the start and end
    preg_replace('`hi`i''hello'$text); // Exactly the same but the i after the ` makes the match insensitive
    preg_replace('#hi\##''hello'$text); // Replaces hi# with hello, the # has to be escaped because it is the start and end character 
    More info in regular expressions help in my sig.


    PHP Code:
    <?php     //line 1

    $str='   test      &     me   ';
    $p='#^[^a-z]+$#';
    $r='_';
    $str=preg_replace($p$r$str);   // here is line 6
    echo $str;

    ?>
    Last edited by Mwnciau; 08-31-2007 at 12:56 PM.

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Thanks, the compiler does not complain now.

    And if i want to replace all the chars which >=1, without a-z, by using '_', how i can do that. my code does not work for this. Could you help, please.

    for example;
    ' test & me ' -> '_test_me_'
    Last edited by kamkam; 08-31-2007 at 12:17 PM.

  • #4
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    <?php     //line 1

    $str='   test      &     me   ';
    $p='#[^a-zA-Z]+#';
    $r='_';
    $str preg_replace($p$r$str);   // here is line 6
    echo $str;

    ?>
    That works fine for me.

  • #5
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Thanks a lot, it does work now.

    but where about the following, would you give me a link, please.

    More info in regular expressions help in my sig.

  • #6
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts

  • #7
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Thanks a lot


  •  

    Posting Permissions

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