-2

The code was working:

$url  = 'http://www.google.com/search?hl=en&tbo=d&site=&source=hp&q=upoznavanje';
$html = file_get_html($url);
preg_match_all('/(?<="><cite>).*?(?=<\/cite><div\ class=)/', $html, $output);
    
foreach ($output[0] as $link) { 
  $link ."<br>"  ;
}

When I added echo $output[0], now I get 0, and nothing in $output[1].

var_dump works and print_r array is there, but how do I get unique values of each without foreach?

var_dump:

array(1) { [0]=> array(10) { [0]=> string(21) "https://www.elmaz.rs/" [1]=> string(47) "https://badoo.com/sr/upoznavanje/serbia/" [2]=> string(39) "https://serbiandating.com/?locale=sr_RS" [3]=> string(30) "https://www.lepoticaizver.com/" [4]=> string(22) "www.prvi-sastanak.net/" [5]=> string(122) "https://www.telegraf.rs/.../1878507-top-5-aplikacija-za-muvanje-ovo-su- najbolji-sajtovi-za-upoznavanje-i-dejt-foto" [6]=> string(137) "https://www.telegraf.rs/.../1863749-dopisivala-sam-se-sa-muskarcinama-na- sajtu-za-upoznavanje-uh-kakve-sam-sve-ponude-dobila-foto" [7]=> string(24) "https://www.iskrica.com/"
Community
  • 1
  • 1
ekvador
  • 1
  • 3
  • Possible duplicate of [Regular Expression (Regex) for HTML parsing in PHP](https://stackoverflow.com/questions/3585087/regular-expression-regex-for-html-parsing-in-php) – Andreas May 23 '19 at 04:11
  • this will work for about 5 minutes because Google is really good at stopping people scraping their search results.https://stackoverflow.com/questions/22657548/is-it-ok-to-scrape-data-from-google-results –  May 23 '19 at 04:18
  • the scraper works fine allways , when i put it in foreach, i do not understand why not work with $output[0] – ekvador May 23 '19 at 04:20
  • `$link . "
    ";` is a pretty pointless line since it doesn't actually _do_ anything. Also, could you post the results of `var_dump($output);`
    – M. Eriksson May 23 '19 at 04:34
  • yes missing echo, i try to remove all not point code , but want to tell that foreach works, there is var_dump: array(1) { [0]=> array(10) { [0]=> string(21) "https://www.elmaz.rs/" [1]=> string(47) "https://badoo.com/sr/upoznavanje/serbia/" [2]=> string(39) "https://serbiandating.com/?locale=sr_RS" [3]=> string(30) "https://www.lepoticaizver.com/" [4]=> string(22) "www.prvi-sastanak.net/" [5]=> string(122) "https://www.telegraf.rs/.../1878507-top-5-aplikacija-za-muvanje-ovo-su- najbolji-sajtovi-za-upoznavanje-i-dejt-foto" – ekvador May 23 '19 at 04:49
  • I short list because limitation – ekvador May 23 '19 at 04:50
  • Please don't post large chunks of code in comments. It's unreadable. Edit your question to include all the information instead. – M. Eriksson May 23 '19 at 04:59
  • Thanks for suggestion,added in post, but still the code not full, i get warning - can not post more then 8 links – ekvador May 23 '19 at 05:19
  • I try now and with some simple input text, not work too, it means preg_match_all i can take data only from loop, or i missing something ? – ekvador May 23 '19 at 05:56
  • Which content do you want to search??? – A.A Noman May 23 '19 at 06:21
  • @A.ANoman you can see clearly on main post what is content, but i try and with simple text, on my side function preg_match_all not work when i try take data with key $output[0] , only when put array in foreach – ekvador May 23 '19 at 10:45
  • @ekvador I had faced same problem. But I search a content from a file not url. Like `IP_Address` search from a file. And it works fine for me – A.A Noman May 23 '19 at 10:53
  • What work exatcly on your side, we have function preg_match_all( regex, input,output ) right, when i take $output[0] , i not get first data in array, only when put array in foreach loop, do you get $output[0] correctly ? – ekvador May 23 '19 at 11:08

1 Answers1

0

I found how to do that with extracting single data from array without loop:

print_r($output[0][0]);
Emma
  • 27,428
  • 11
  • 44
  • 69
ekvador
  • 1
  • 3