-2

I meet a trouble with string. I use file_get_contents($url) to get content of a website.

$content = tile_get_contents($url);
$arrTmp = explode('>',$content);
var_dump (trim( $arrTmp[100]) ) => result is: string '<td width="33.3333333333%" valign="top"'
echo trim( $arrTmp[100]); => nothing.

Thanks in advance!

Tran Hieu
  • 3
  • 1

1 Answers1

0

your sample seems to be incomplete

you define $arr

where does $arrTmp comes from?

what is $i? is it defined?

whats between the var_dump and echo?

and whats the purpose of this Action?

EDIT: just tested:

$url = 'http://w3schools.com/tags/ref_standardattributes.asp'; 
$ctx = stream_context_create(array('http'=> array( 'timeout' => 60 ) )); 
$content = file_get_contents($url, false, $ctx); 
$arrTmp = explode('>',$content);
for($i = 0; $i < count($arrTmp); $i++)
{ 
    echo '<br />'; 
    echo 'Res->'.htmlspecialchars(trim($arrTmp[$i])); 
}

result:

Res-><!DOCTYPE html
Res-><html lang="en-US"
Res-><head
Res-><title

and so on ...

maybe a server-setup-issue? but i have no idea what it could be at your side ...

mech
  • 617
  • 6
  • 16
  • Thank you! I edited the content of my question. I explode content of a web site by '>', then I want to echo every value of the array, but I can not show them by echo function, then I can show it by var_dump function. – Tran Hieu Nov 09 '14 at 15:09
  • i think preg_split would be better, but your described behavior is really strange ... i think you've checked the source of the page with your test-Output (because if the browser interpretes the " – mech Nov 09 '14 at 15:21
  • That is my code: $url = 'http://www.w3schools.com/tags/ref_standardattributes.asp'; $ctx = stream_context_create(array('http'=> array( 'timeout' => 60, // 60 Seconds = 1 Minutes ) )); $content = file_get_contents($url, false, $ctx); $arrTmp = explode('>',$content); for($i = 0; $i < count($arrTmp); $i++){ var_dump($arrTmp[$i]); echo '
    '; echo 'Res->'.($arrTmp[$i]); } Thanks!
    – Tran Hieu Nov 09 '14 at 15:35
  • Thank you very much! :D That is all things I need. :) – Tran Hieu Nov 09 '14 at 15:45