Regular Expressions Question

Discussion in 'PHP' started by palespyder, Nov 10, 2005.

  1. #1
    Anyone can translate the following into regular expressions for me?

    and

    These are giving me trouble ;)
     
    palespyder, Nov 10, 2005 IP
  2. dataman

    dataman Peon

    Messages:
    94
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What do you want to do?

    Just match, or match and replace!

    jb
     
    dataman, Nov 10, 2005 IP
  3. palespyder

    palespyder Psycho Ninja

    Messages:
    1,254
    Likes Received:
    98
    Best Answers:
    0
    Trophy Points:
    168
    #3
    I need to match the data between those two tags, sorry ;)
     
    palespyder, Nov 10, 2005 IP
  4. dataman

    dataman Peon

    Messages:
    94
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi

    If you just want to match.... (use 1 of these)

    <?
    
    /* if match found execute if() */
    
    if ( preg_match ( '!(<\!-- Instance(Begin|End)Editable( name="MainBody")? -->)!s', $str ) )
    {
    	echo 'match found';
    }
    
    /* if match not found execute if() */
    
    if ( ! preg_match ( '!(<\!-- Instance(Begin|End)Editable( name="MainBody")? -->)!s', $str ) )
    {
    	echo 'match not found';
    }
    
    ?>
    PHP:

    If you want the data beween the 2 tags then use str_ type functions....

    example...

    <?
    
    $str = 'mmmmmmmmmmmmmmmmmmmmmm  
    <!-- InstanceBeginEditable name="MainBody" -->
    ,,,,,,,,,,nnnnnnnnnnn
    nnnnnnnnnn
    jhhhhh54
    766666
    <!-- InstanceEndEditable -->
    666666
    66666666346';
    
    
    $start = '<!-- InstanceBeginEditable name="MainBody" -->';
    $stops = '<!-- InstanceEndEditable -->';
    
    
    echo substr ( $str, ( $pos = ( strpos ( $str, $start ) + strlen ( $start ) ) ), ( strpos ( $str, $stops, $pos ) - $pos ) );
    
    
    ?>
    PHP:

    jb
     
    dataman, Nov 10, 2005 IP
    palespyder likes this.
  5. palespyder

    palespyder Psycho Ninja

    Messages:
    1,254
    Likes Received:
    98
    Best Answers:
    0
    Trophy Points:
    168
    #5
    Works perfectly, Thank man!
     
    palespyder, Nov 11, 2005 IP