Hi , I want to get content located between <div class="tresc"> </div> , from website and show it on mine ,Im using file get content to obtain web source , then preg match all to get content between divs , but its not working , return nothing the target div <div class="tresc">Od poniedziałku do piątku o godz. <strong>19:50</strong><br>Weekendy o godz. <strong>19:45</strong></div> PHP: And my code , propably the pattern is wrong , so plz help me <?php function file_get_contents_utf8($fn){ $fn ="http://uwaga.onet.pl/index.html"; $content = file_get_contents($fn); return mb_convert_encoding($content, 'UTF-8', mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true)); } function findinside($tag, $content) { $pattern = '/<div class='.preg_quote($tag).' >(.*?)<div>/si'; preg_match_all($pattern, $content, $m); return $m[1]; } $tag = 'tresc'; $data="<div class=\"tresc\">text1<strong>text2</strong><br><strong>text3</strong></div>"; $out = findinside($tag, $data); print_r ($out); PHP:
Before I look through the code, have you made sure you can use file_get_contents with URLs? Sometimes hosts disallow this function as a security feature. Check that allow_url_fopen is enabled in a phpinfo file.
<?php function file_get_contents_utf8( $fn ) { /* We'll run with your function */ $content = file_get_contents( $fn ); return mb_convert_encoding( $content, 'UTF-8', mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true) ); } $file = file_get_contents_utf8('http://uwaga.onet.pl/index.html'); preg_match('/<div class=tresc>(.*?)<\/div>/', str_replace(array("\n", "\r"), ' ', $file), $matches); list(, $value) = $matches; echo $value; ?> PHP: Returns: Od poniedziaÂłku do piÂątku o godz. <strong>19:50</strong><br>Weekendy o godz. <strong>19:45</strong> Code (markup):