Quick help on preg_match

Discussion in 'PHP' started by Subikar, Dec 10, 2009.

  1. #1
    Hi All

    I need a text from a string

    The string is
    $mystring = "<p>{loadposition plans comas grv}</p>";

    I need the result "plans comas grv" from the string for someone who is good in preg_match can solve in few min and that will help me.

    Waiting for your valuable post.

    Thanks,
    Subikar
     
    Subikar, Dec 10, 2009 IP
  2. Wogan

    Wogan Peon

    Messages:
    81
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    0
    #2
    preg_match( "/<p>{loadposition (.*)}<\/p>/Uise" , $string, $matches);
    PHP:
     
    Wogan, Dec 11, 2009 IP
  3. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    preg_match( "%<p>loadposition (.*?)</p>%" , $input, $output);
    PHP:
    The text will be in $output[1]
    Note that the previous regex won't work due to the curly braces
     
    JAY6390, Dec 11, 2009 IP
  4. Wogan

    Wogan Peon

    Messages:
    81
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    0
    #4
    Nope, previous regex works just fine. Just tested it on PHP 5.3.0. And the curly braces is a requirement - your regex doesn't account for them (just tested that too).
     
    Wogan, Dec 11, 2009 IP
  5. unigogo

    unigogo Peon

    Messages:
    286
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Not just curly braces. / has to be escaped \/
     
    unigogo, Dec 12, 2009 IP
  6. Wogan

    Wogan Peon

    Messages:
    81
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    0
    #6
    And it is - <\/p>.
     
    Wogan, Dec 12, 2009 IP