...

View Full Version : Regular Expression Question



kevinkhan
10-28-2009, 06:33 PM
Hi Everyone..

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




<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..




$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);

Phil Jackson
10-28-2009, 08:33 PM
#<li\s+class=\"vehicle\-location\"><span\s+title="([^\"]+)">London</span></li>#is

$title = $match[1];



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum