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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts

    Regular Expression Question

    Hi Everyone..

    I want to extract the title an link in the following html file but only if the location is london


    PHP Code:
    <li >
      <
    ul class="search-result" id="AdvertRow12">
        <
    li class="vehicle-images"><a href="http:\\www.mydomain.com" title="9 photos of Alfa Romeo 147 Diesel JTDM 120bhp No Mileage !"><span>9</span></a></li>                                 
        <
    li class="vehicle-make-model"><a title="Alfa Romeo 147 Diesel JTDM 120bhp No Mileage !" href="http://www.mydomain.com/search/Alfa-Romeo/147/Diesel-J/200938195255441/advert?channel=CARS">Alfa Romeo 147 Diesel JTDM &hellip;</a></li>                  
        <
    li class="vehicle-approved"><img src="http://images.mydomain.com/dealer-resource/programme/20x20/keary.gif" /></li>                  
        <
    li class="vehicle-year">2009</li>               
        <
    li class="vehicle-seller"><span class="dealer-simi">Dealer</span></li>                              
        <
    li class="vehicle-location"><span title="Kearys Lexus">London</span></li>         
        <
    li class="vehicle-mileage">2</li>
        <
    li class="vehicle-colour"><span title="Metallic Grey" class="grey"><em>Grey</em></span></li>
        <
    li class="vehicle-engine">1.9</li
        <
    li class="vehicle-price">&euro;20,900</li>
      </
    ul>
    </
    li>

    <
    li >
      <
    ul class="search-result" id="AdvertRow12">
        <
    li class="vehicle-images"><a href="http:\\www.mydomain.com" title="9 photos of Alfa Romeo 147 Diesel JTDM 120bhp No Mileage !"><span>9</span></a></li>                                 
        <
    li class="vehicle-make-model"><a title="Alfa Romeo 147 Diesel JTDM 120bhp No Mileage !" href="http://www.mydomain.com/search/Alfa-Romeo/147/Diesel-J/200938195255441/advert?channel=CARS">Alfa Romeo 147 Diesel JTDM &hellip;</a></li>                  
        <
    li class="vehicle-approved"><img src="http://images.mydomain.com/dealer-resource/programme/20x20/keary.gif" /></li>                  
        <
    li class="vehicle-year">2009</li>               
        <
    li class="vehicle-seller"><span class="dealer-simi">Dealer</span></li>                              
        <
    li class="vehicle-location"><span title="Kearys Lexus">Leeds</span></li>         
        <
    li class="vehicle-mileage">2</li>
        <
    li class="vehicle-colour"><span title="Metallic Grey" class="grey"><em>Grey</em></span></li>
        <
    li class="vehicle-engine">1.9</li
        <
    li class="vehicle-price">&euro;20,900</li>
      </
    ul>
    </
    li>

    <
    li >
      <
    ul class="search-result" id="AdvertRow12">
        <
    li class="vehicle-images"><a href="http:\\www.mydomain.com" title="9 photos of Alfa Romeo 147 Diesel JTDM 120bhp No Mileage !"><span>9</span></a></li>                                 
        <
    li class="vehicle-make-model"><a title="Alfa Romeo 147 Diesel JTDM 120bhp No Mileage !" href="http://www.mydomain.com/search/Alfa-Romeo/147/Diesel-J/200938195255441/advert?channel=CARS">Alfa Romeo 147 Diesel JTDM &hellip;</a></li>                  
        <
    li class="vehicle-approved"><img src="http://images.mydomain.com/dealer-resource/programme/20x20/keary.gif" /></li>                  
        <
    li class="vehicle-year">2009</li>               
        <
    li class="vehicle-seller"><span class="dealer-simi">Dealer</span></li>                              
        <
    li class="vehicle-location"><span title="Kearys Lexus">London</span></li>         
        <
    li class="vehicle-mileage">2</li>
        <
    li class="vehicle-colour"><span title="Metallic Grey" class="grey"><em>Grey</em></span></li>
        <
    li class="vehicle-engine">1.9</li
        <
    li class="vehicle-price">&euro;20,900</li>
      </
    ul>
    </
    li>


    <
    li >
      <
    ul class="search-result" id="AdvertRow12">
        <
    li class="vehicle-images"><a href="http:\\www.mydomain.com" title="9 photos of Alfa Romeo 147 Diesel JTDM 120bhp No Mileage !"><span>9</span></a></li>                                 
        <
    li class="vehicle-make-model"><a title="Alfa Romeo 147 Diesel JTDM 120bhp No Mileage !" href="http://www.mydomain.com/search/Alfa-Romeo/147/Diesel-J/200938195255441/advert?channel=CARS">Alfa Romeo 147 Diesel JTDM &hellip;</a></li>                  
        <
    li class="vehicle-approved"><img src="http://images.mydomain.com/dealer-resource/programme/20x20/keary.gif" /></li>                  
        <
    li class="vehicle-year">2009</li>               
        <
    li class="vehicle-seller"><span class="dealer-simi">Dealer</span></li>                              
        <
    li class="vehicle-location"><span title="Kearys Lexus">Leeds</span></li>         
        <
    li class="vehicle-mileage">2</li>
        <
    li class="vehicle-colour"><span title="Metallic Grey" class="grey"><em>Grey</em></span></li>
        <
    li class="vehicle-engine">1.9</li
        <
    li class="vehicle-price">&euro;20,900</li>
      </
    ul>
    </
    li
    I set up this php code but not sure how i can construct the regular expression. Can anyone help me out please..

    PHP Code:

    $strURL 
    $_POST["crawlUrl"];

    function 
    getMatches($strMatch,$strContent
      {
            if(
    preg_match_all($strMatch,$strContent,$objMatches))
        {
                return 
    $objMatches;
            }
            return 
    "";
        }


    $strContent = @file_get_contents($strListingUrl);
                    
                
    $strListMatches '!<div class="title">(.*)</div>!isU';
                
    $objListMatches getMatches($strListMatches,$strContent); 

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    #<li\s+class=\"vehicle\-location\"><span\s+title="([^\"]+)">London</span></li>#is

    $title = $match[1];
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 


  •  

    Posting Permissions

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