Jump to content

kevinkhan

Members
  • Posts

    142
  • Joined

  • Last visited

Everything posted by kevinkhan

  1. Sorry i left out the equals sign it worked fine but now i change the code to this and when i run the script i get nothing <?php $strContent = file_get_contents('http://www.carzone.ie/search/results?searchsource=browse&cacheBuster=1256829754944212'); function getMatches($strMatch,$strContent) { if(preg_match_all($strMatch,$strContent,$objMatches)) { return $objMatches; } return ""; } $strMatch ='#<li class="vehicle"><a href="([^"]*)">([^<]*)</a>#is'; $objListMatches = getMatches($strMatch,$strContent); $sUrl = $objListMatches[1]; $sTitle = $objListMatches[2]; print_r($sUrl); echo "<br />"; print_r($sTitle); ?> Does the regular expression have to change now? Im looking for the same piece of html code in the carzone.ie url..
  2. This is what im getting when i run the script Parse error: parse error in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\carzoneCrawler\preg_match.php on line 19
  3. Please have a look at this script and tell me what is wrong.. Im trying to extract the link and whats between <a href> </a> and i only want to take the ones which have a class of class="vehicle" <?php function getMatches($strMatch,$strContent) { if(preg_match_all($strMatch,$strContent,$objMatches)) { return $objMatches; } return ""; } $strContent = '<li class="vehicle"><a href="http://www.domain.ie/abc?/">vehicle1</a> <li class="bus"><a href="http://www.domain.ie/abc?/">Alfa Romeo 147</a> <li class="vehicle"><a href="http://www.domain.ie/abc?/">vehicle2</a> <li class="van"><a href="http://www.domain.ie/abc?/">Alfa Romeo 147</a> <li class="van"><a href="http://www.domain.ie/abc?/">Alfa Romeo 147</a>'; $strMatch "#<li class=\"vehicle\"><a href=\"(.*)\">(.*)</a>#"; $objListMatches = getMatches($strMatch,$strContent); $sUrl = $objListMatches[1]; $sTitle = $objListMatches[2]; echo $sUrl; echo "<br />"; echo $sTitle; Any help will be greatly appreciated
  4. Would you be able to give a small simple example Im only at the beginning stages of learning php...
  5. 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 …</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">€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 …</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">€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 …</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">€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 …</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">€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);
  6. in my original code i had '!<li class="vehicle-images" href="(.*)" title="(.*)"><span>(.*)</span></a></li>!isU'; as the regular expression What does the ! before the <li and after the closeing </li> mean and also what is the isU about do you know???
  7. No its still not working.. This is the code im using now <? set_time_limit(-1); // This allows the script to run infinitly ob_implicit_flush(1); // ob is output buffering // ob_implicit_flush(1); That is for browser flush // if we set this, and other code, it uses to show the results running // if you remove these, it will show loading and wont display the messages // only get message after the script is completed // which means Hangs // code needed for running lengthy scripts flush(); // flush, just flushes the buffer // attempts to push current output all the way to the browser // a buffer is a part of RAM used for temporary storage of data that is waiting to be sent to a device ob_end_flush(); $strURL = ""; if(isset($_POST["crawlUrl"])) $strURL = $_POST["crawlUrl"]; //Function to find Matches for Given Expression $strMatch and in the Content $strContent function getMatches($strMatch,$strContent) { if(preg_match_all($strMatch,$strContent,$objMatches)) { return $objMatches; } return ""; } ?> <html> <head> <title>Project - Extracting Title of ads on www.carzone.ie </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form name="frmExtract" method="post" action=""> URL: <input name="crawlUrl" type="text" id="crawlUrl" size="50" value="<? print $strURL;?>" > <input name="btnCrawl" type="submit" value="Crawl Data"> </form> <br> <br> <? if($strURL != "") { $strListingUrl = $strURL; while(true) { //Get the Content from the URL // file_get_contents — Reads entire file into a string $strContent = file_get_contents($strListingUrl); //Expression to match the Link and Title $strListMatches = '<li class="vehicle-images"><a href="([^"]*)" title="([^"]*)"><span>([^<]*)</span></a></li>'; $objListMatches = getMatches($strListMatches,$strContent); print_r($objListMatches[1]); if($objListMatches == "" || count($objListMatches[1]) == 0) { print "No List found or Invalid URL<br>"; } } } ?> </body> </html>
  8. im looking to extract the information in lines 652 to 736 of the source code of this url http://www.carzone.ie/search/results?searchsource=browse&cacheBuster=1256634750309620#nParam=200590%2B219%2B147&sortby=County|1&channel=CARS&currency=EUROS&searchResultsView=SPREADSHEET&maxrows=30&page=1 anything with this pattern <li class="vehicle-images"><a href="http://www.carzone.ie/search/Alfa-Romeo/145/1.6-TS-1/200840190250089/advert?channel=CARS" title="7 photos of Alfa Romeo 145 1.6 TS 16V JUNIOR"><span>7</span></a></li>
  9. Hi guys.. Im trying to learn php and im running into a few problems ok im trying to extract the titles of ads from this url http://www.carzone.ie/search/results?searchsource=browse&cacheBuster=1256634750309620#nParam=200590%2B219%2B147&sortby=County|1&channel=CARS&currency=EUROS&searchResultsView=SPREADSHEET&maxrows=30&page=1 Here is the script that i am using to try and do this set_time_limit(-1); ob_implicit_flush(1); flush(); ob_end_flush(); $strURL = ""; if(isset($_POST["crawlUrl"])) $strURL = $_POST["crawlUrl"]; function getMatches($strMatch,$strContent) { if(preg_match_all($strMatch,$strContent,$objMatches)) { return $objMatches; } return ""; } ?> <html> <head> <title>Project - Extracting Title of ads on www.carzone.ie </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form name="frmExtract" method="post" action=""> URL: <input name="crawlUrl" type="text" id="crawlUrl" size="50" value="<? print $strURL;?>" > <input name="btnCrawl" type="submit" value="Crawl Data"> </form> <br> <br> <? if($strURL != "") { $strListingUrl = $strURL; while(true) { //Get the Content from the URL // file_get_contents — Reads entire file into a string $strContent = file_get_contents($strListingUrl); //Expression to match the Link and Title $strListMatches = '!<li class="vehicle-images" href="(.*)" title="(.*)"><span>(.*)</span></a></li>!isU'; $objListMatches = getMatches($strListMatches,$strContent); print_r($objListMatches[1]); if($objListMatches == "" || count($objListMatches[1]) == 0) { print "No List found or Invalid URL<br>"; } } } Can anybody tell me what im doing wrong please i keep getting "No List found or Invalid URL"
  10. $strListMatches = '!<a class="details" href="(.*)" title="(.*)">(.*)</a>!isU';
  11. Hi there. Im have a problem uploading a database in phpMyAdmin Im getting this error "No data was received to import. Either no file name was submitted, or the file size exceeded the maximum size permitted by your PHP configuration. See FAQ 1.16." Next to upload file it says (Max: 8,192 KiB) What is the recomended values for upload_max_filesize, memory_limit and post_max_size in the php.ini configuration file.
  12. Yes i cant say that i know much about this... Would you know of any good site that i could learn more about this topic? Thanks in advance Kevin
  13. yes its kind of weird All that i type into the input field is Kevin Khan but when i open email it gives kevin.khan@ (some weird name) I think its the name of the server im not sure.. i know novara.ie is where im hosting the site..
  14. Thanks for your help.. This is a bit better.. However this is what its giving me now when i receive email Under sender it gives this Kevin.Khan@pemlinweb02.novara.ie I want it to be just Kevin Khan or what ever user puts into text field uner name Thanks for your time...
  15. Hi Everyone, Just need a small bit of advice if anyone can help.. I have a contact form on my site and it sends all the input fields however when i get an email i want the persons name to come up as the sender.. At the moment wat comes up is userx100175... This is the script below <?php $to = "info@corkbouncingcastles.com"; $subject = "Cork Bouncing Castles Inquiry!"; $body = "First Name: " . $_POST['name'] . "\nEmail: " . $_POST['email'] . "\nPhone Number: " . $_POST['number'] . "\nMessage: " . $_POST['msg']; $headers = 'Reply-To: '. $_POST['email'] . "\r\n" . 'X-Mailer: PHP/' . phpversion(); if (mail($to, $subject, $body, $headers)) { echo("<p>Thanks for submitting your enquiry. We will be in touch with you soon.</p> <p>If you would like any further assistance you can call us on 086-2430367 and we will be glad to answer any questions you might have.</p>"); } else { echo("<p>Message delivery failed. Please go back to the Contact Us page and fill out the contact form again or call us on 086-2430367 to get an instant quote to hire one of our bouncing castles.</p>"); } ?> Thanks to anyone that can help...
  16. Hi guys, I have a script that extracts numbers from a .txt file.. but it list the numbers in these formats 087-9850714 (087) 9850714 (087)9850714 087 9850714 0879850714 Is there anyway of changing these numbers and putting them all in this format 0879850714 0879850714 0879850714 0879850714 0879850714 [attachment deleted by admin]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.