Help with preg_match() extract a string

Discussion in 'PHP' started by Yazari, Jul 27, 2007.

  1. #1
    Hello,
    I have to extract a string (All characters) between two tags :

    Exemple :

    
    $var="some text 1
    <title>Hello Every - Body * / dd 0,0,44</title>
    some text 2";
    
    Code (markup):
    I need to extract Hello Every - Body * / dd 0,0,44 between the title tags from $var

    I think it may be done using preg_match but i don't know how to use [0-9] [a-z] stuff...

    Can YOU PLEASE HELP me ?
     
    Yazari, Jul 27, 2007 IP
  2. pruad

    pruad Peon

    Messages:
    71
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
    
    $var="some text 1
    <title>Hello Every - Body * / dd 0,0,44</title>
    some text 2";
    
    if(preg_match('/<title>(.+)<\/title>/', $var, $matches)) print $matches[1];
    
    ?>
    Code (markup):
     
    pruad, Jul 27, 2007 IP
    DeViAnThans3 likes this.
  3. Yazari

    Yazari Peon

    Messages:
    180
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    and that's it :| (.+)
     
    Yazari, Jul 27, 2007 IP
  4. pruad

    pruad Peon

    Messages:
    71
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    not working?
     
    pruad, Jul 27, 2007 IP
  5. Yazari

    Yazari Peon

    Messages:
    180
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i'll give it a try tomorrow i'm not on my computer.
     
    Yazari, Jul 27, 2007 IP
  6. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Seems to be working very well for me, just tested. :)
    Tnx
     
    DeViAnThans3, Jul 27, 2007 IP
  7. pruad

    pruad Peon

    Messages:
    71
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Welcome =)
     
    pruad, Jul 28, 2007 IP