Help with RegEx

Discussion in 'PHP' started by astrazone, Oct 20, 2009.

  1. #1
    I started learning RegEx and I want to take some data from a website(learning purpose only).

    Please help me with preg_match_all.

    this is what I need to get

    <li> 
        <a href="/play/3614/crush-the-castle" title="Crush the Castle"><img src="/files/thumbnails/crush-the-castle-3614.jpg" alt="Crush the Castle" width="60" height="60" /></a> 
        <h5>
        	<a href="/play/3614/crush-the-castle" title="Crush the Castle" class="">Crush the Castle</a>
        </h5> 
        <p class="plays">13,106,764 plays</p> 
        <p class="rating">Rating: 9/10</p> 
    </li>
    PHP:

    I need something like:

    link:/play/3614/crush-the-castle
    title:Crush the Castle
    img:/files/thumbnails/crush-the-castle-3614.jpg
    alt:Crush the Castle
    and sizes..

    Please explain what you do in details..

    Thanks
     
    astrazone, Oct 20, 2009 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    mastermunj, Oct 20, 2009 IP
  3. unigogo

    unigogo Peon

    Messages:
    286
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    unigogo, Oct 20, 2009 IP
  4. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #4
    Simple pattern
    
    $pattern = "/<a href="([^"]+)" title="([^"]+)"><img src="([^"]+)" alt="([^"]+)" width="([^"]+)" height="([^"]+)" \/>/";
    
    
    PHP:
    outputs
    
    Array
    (
        [0] => <a href="/play/3614/crush-the-castle" title="Crush the Castle"><img src="/files/thumbnails/crush-the-castle-3614.jpg" alt="Crush the Castle" width="60" height="60" />
        [1] => /play/3614/crush-the-castle
        [2] => Crush the Castle
        [3] => /files/thumbnails/crush-the-castle-3614.jpg
        [4] => Crush the Castle
        [5] => 60
        [6] => 60
    )
    
    Code (markup):
     
    Gray Fox, Oct 20, 2009 IP