Hellow ppl, I got a problem with cURL, I want to get some info from another site and save it in database. Regex is 100% right but it still doesn't shows all the results <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://site.com/'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/'); $pagina = curl_exec($ch); curl_close($ch); if(empty($page)) { echo "Nothing!"; } else { if(preg_match_all("/<td\salign=\"right\"[^>]*><a href=\"([^<]*)\"[^>]*><img src=\"([^<]*)\" [^>]*><\/a><br \/>([^<]*)<\/td>/is", $page, $matches)) { echo '<pre>'; var_dump($matches); echo '</pre>'; $i = $i++; foreach($matches as $i => $match) { $match = $match; echo '<br>' . $matches[1][$i]; } } else { echo "error!"; } } ?> PHP: the var_dump shows like 30-40 results but foreach() only 4-5 what am i doing wrong? Please help someone
Why is there $match = $match ? And haven't you tried going through one-dimensional array ? Perhaps doing this: foreach($matches as $blah) { echo $blah; } I'm not an expert with php but I would def. try something like that ..
Thanks for reply... Ya you right $match = $match is totally useless But what you say will not work $blah[1]; will give only the first result... What you mean with one-dimensional array? can you explain in maybe please?
Give this a go: <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://site.com/'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/'); $pagina = curl_exec($ch); curl_close($ch); if(empty($page)) { echo "Nothing!"; } else { if(preg_match_all("/<td\salign=\"right\"[^>]*><a href=\"([^<]*)\"[^>]*><img src=\"([^<]*)\" [^>]*><\/a><br \/>([^<]*)<\/td>/is", $page, $matches)) { echo '<pre>'; var_dump($matches); echo '</pre>'; $i++; foreach($matches[1] as $match) { echo '<br>' . $match; } } else { echo "error!"; } } ?> PHP:
$matches[1] will show only the first "([^<]*)" $matches[0] will show everything right... but i can't add it like that to the db
yes i tried it shows only the link (in my case) foreach($matches[1] as $url) foreach($matches[2] as $image) this will give the url and img... but it duplicates it to many times... i rly don't know what i'm doing wrong...