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

Thread: Regex question

  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Regex question

    say I've the following string :
    PHP Code:
    $var '[quote comment="456454"]dgdada[/quote]fhbsh sfhsr hrh wsryh rsyrsy'
    I want to delete the character between the quote tags

    the final string should be like this :
    PHP Code:
    fhbsh sfhsr hrh wsryh rsyrsy 
    note that this form :
    PHP Code:
    [quote comment
    at the beginning of the string

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    PHP Code:
    $var preg_replace'/\[quote[^\]]*\].*\[\/quote\]/Usi'''$var ); 

  • #3
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by kbluhm View Post
    PHP Code:
    $var preg_replace'/\[quote[^\]]*\].*\[\/quote\]/Usi'''$var ); 
    it didn't work
    Last edited by Me & I; 08-03-2007 at 10:25 PM.

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Worked for me.

    This code:
    PHP Code:
    <?php

    $var 
    '[quote comment="456454"]dgdada[/quote]fhbsh sfhsr hrh wsryh rsyrsy';

    $var preg_replace'/\[quote[^\]]*\].*\[\/quote\]/Usi'''$var );

    echo 
    $var;

    ?>
    Outputs:
    Code:
    fhbsh sfhsr hrh wsryh rsyrsy
    Last edited by kbluhm; 08-04-2007 at 03:02 AM.


  •  

    Posting Permissions

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