Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]preg_match_all - problem
Forum PHP.pl > Forum > Przedszkole
Kapitan123
Witam, mam problem z funkcją preg_match_all. Wyciągnąłem z kodu strony DIV (<div class="fcb">), ale wyświetla mi obok zawartości DIVa coś takiego:

Array ( [0] => Array ( [0] =>
Mozilla Firefox
[1] =>
Google Chrome
[2] =>
Safari
[3] =>
Microsoft Internet Explorer

Chciałbym, żeby wyświetlało samą zawartość DIV, czyli "Mozilla Firefox", "Google Chrome", itd...

Mój kod:

  1. <?php
  2.  
  3. $str = file_get_contents('http://facebook.com/');
  4.  
  5. preg_match_all('@<div class="fcb">(.*)</div>@Uis', $str, $div);
  6.  
  7. print_r($div);
  8.  
  9.  
  10. ?>


Fragment kodu strony:

  1. <ul class="uiList mvm uiListBulleted"><li class="uiListVerticalItemBorder"><div class="fcb"><a href="http://www.getfirefox.com" onmousedown="UntrustedLink.bootstrap($(this), &quot;UAQGoAJ6b&quot;, event, bagof(null));" rel="nofollow" target="_blank"> Mozilla Firefox </a></div></li>
  2.  
  3. <li class="uiListVerticalItemBorder"><div class="fcb"><a href="http://www.google.com/chrome/" onmousedown="UntrustedLink.bootstrap($(this), &quot;QAQGNyBl7&quot;, event, bagof(null));" rel="nofollow" target="_blank"> Google Chrome </a></div></li>
  4.  
  5. <li class="uiListVerticalItemBorder"><div class="fcb"><a href="http://www.apple.com/safari" onmousedown="UntrustedLink.bootstrap($(this), &quot;RAQECUhN8&quot;, event, bagof(null));" rel="nofollow" target="_blank"> Safari </a></div></li>
  6.  
  7. <li class="uiListVerticalItemBorder"><div class="fcb"><a href="http://www.microsoft.com/ie" onmousedown="UntrustedLink.bootstrap($(this), &quot;hAQHzy3bt&quot;, event, bagof(null));" rel="nofollow" target="_blank"> Microsoft Internet Explorer </a></div></li></ul>
crocodillo
zamiast print_r($div):
  1. echo implode(' ',$div);
Kapitan123
Teraz wyskakuje

Array Array
crocodillo
Nie przeczytałem dokładnie całego Twojego pytania, zasugerowałem się tylko wynikiem.

  1. $str = file_get_contents('http://facebook.com/');
  2. preg_match_all('@<div class="fcb">.*_blank">(.*)</a>@Uis', $str, $div);
  3.  
  4. if (isset($div[1])) {
  5. foreach($div[1] as $a) {
  6. echo $a.'<br />';
  7. }
  8. }
Kapitan123
Działa smile.gif Dzięki smile.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.