Can var_dump a string but can not echo the string

385 views Asked by At

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!

1

There are 1 answers

4
mech On BEST ANSWER

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 ...