Modernvox Posted October 30, 2009 Share Posted October 30, 2009 Would like to know if i am using the correct regex to return a link similar to sale-twqea-1444978669@craigslist.org Problem is i keep getting a Parse error: syntax error, unexpected $end in C:\xampp\htdocs\test4.php on line 45? function curlURL($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2'); $output = curl_exec($curl); return $output; } $curlResults = curlURL("http://southcoast.craigslist.org/sss/"); $pattern = '#<a href="(/[a-z]{3}/\d{10}\.html)">#'; preg_match_all( $pattern, $curlResults, $matches); echo "<pre>\n"; echo "Links:\n\n"; foreach ($matches[1] as $link): echo "\t" . '<a href="' . $link . '" target="_BLANK">' . $link . '</a>' . "\n"; endforeach; echo '</pre>'; echo file_get_contents("http://southcoast.craigslist.org".$link); $pattern = '#<sale-([a-z0-9]?/\d{10}\.html)">#'; //This is the attempted match for the email preg_match_all( $pattern, $matches); foreach ($matches[1] as $address): $dbx= mysql_connect("localhost", "peter", ""); //include before any database implematation if (!$dbx) { die('Could not connect: ' . mysql_error()); } mysql_SELECT_db("Craigslist", $dbx); mysql_Query("INSERT INTO addresses (sale_items) VALUES ('$address'); mysql_close($dbx); ?> Quote Link to comment https://forums.phpfreaks.com/topic/179695-solved-preg_match_all/ Share on other sites More sharing options...
trq Posted October 30, 2009 Share Posted October 30, 2009 You never close your foreach. Quote Link to comment https://forums.phpfreaks.com/topic/179695-solved-preg_match_all/#findComment-948127 Share on other sites More sharing options...
Modernvox Posted October 31, 2009 Author Share Posted October 31, 2009 You never close your foreach. Thanks , but that does nothing for me. Quote Link to comment https://forums.phpfreaks.com/topic/179695-solved-preg_match_all/#findComment-948153 Share on other sites More sharing options...
trq Posted October 31, 2009 Share Posted October 31, 2009 Why does that do nothing for you? Your missing an endforeach; Quote Link to comment https://forums.phpfreaks.com/topic/179695-solved-preg_match_all/#findComment-948164 Share on other sites More sharing options...
Modernvox Posted October 31, 2009 Author Share Posted October 31, 2009 Why does that do nothing for you? Your missing an endforeach; I added the endforeach; and the results were the same. I did however add the following and got it to work, but now i am trying to open on =e of them with no luck yet. Error states 2 parameters required.. <?php function curlURL($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2'); $output = curl_exec($curl); return $output; } $curlResults = curlURL("http://southcoast.craigslist.org/sss/"); $pattern = '#<a href="(/[a-z]{3}/\d{10}\.html)">#'; preg_match_all( $pattern, $curlResults, $matches); echo "<pre>\n"; echo "Links:\n\n"; foreach ($matches[1] as $link): echo "\t" . '<a href="' . $link . '" target="_BLANK">' . $link . '</a>' . "\n"; endforeach; echo '</pre>'; echo file_get_contents("http://southcoast.craigslist.org".$link); $pattern = '#<sale-([a-z0-9]?/\d{10}\.html)">#'; preg_match( $pattern, $matches); print_r ($matches[0]); //Have 99 available links to click $fp= fopen($matches[2]); //How can i choose one and open it? ?> Quote Link to comment https://forums.phpfreaks.com/topic/179695-solved-preg_match_all/#findComment-948166 Share on other sites More sharing options...
trq Posted October 31, 2009 Share Posted October 31, 2009 but now i am trying to open on =e of them with no luck yet Sorry, but that makes no sense at all from here. Error states 2 parameters required.. In regard to what function? Quote Link to comment https://forums.phpfreaks.com/topic/179695-solved-preg_match_all/#findComment-948174 Share on other sites More sharing options...
Modernvox Posted October 31, 2009 Author Share Posted October 31, 2009 but now i am trying to open on =e of them with no luck yet Sorry, but that makes no sense at all from here. Error states 2 parameters required.. In regard to what function? Yeah, I am getting lost, sorry. I mean to say. I added the endforeach with no luck. What i have on my screen now is the active links list and ONE open link. I am attempting to copy the email address from the ONE open link using the preg_match function #<sale-([a-z0-9]?/\d{10}\.html)">#' so I may send to DB. I just keep getting errors when i attempt to copy the email whether i use foreach, if etc.. I just don't have enough experience to produce the proper code. I hope I sound a little more clear. Happy Halloween Quote Link to comment https://forums.phpfreaks.com/topic/179695-solved-preg_match_all/#findComment-948180 Share on other sites More sharing options...
trq Posted October 31, 2009 Share Posted October 31, 2009 What are the errors? Were not mind readers. Quote Link to comment https://forums.phpfreaks.com/topic/179695-solved-preg_match_all/#findComment-948191 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.