【问题标题】:Can var_dump a string but can not echo the string可以 var_dump 字符串但不能回显字符串
【发布时间】:2015-01-05 21:53:22
【问题描述】:

我遇到了字符串问题。 我使用 file_get_contents($url) 来获取网站的内容。

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

提前致谢!

【问题讨论】:

    标签: url echo var-dump


    【解决方案1】:

    您的样本似乎不完整

    你定义$arr

    $arrTmp 是从哪里来的?

    $i 是什么?定义了吗?

    var_dump 和 echo 之间有什么关系?

    这个行动的目的是什么?

    编辑: 刚刚测试:

    $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])); 
    }
    

    结果:

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

    等等……

    可能是服务器设置问题?但我不知道它会在你身边......

    【讨论】:

    • 谢谢!我编辑了我的问题的内容。我用'>'展开一个网站的内容,然后我想回显数组的每个值,但是我不能通过回显函数显示它们,然后我可以通过var_dump函数显示它。
    • 我认为 preg_split 会更好,但你描述的行为真的很奇怪......我认为你已经用你的测试输出检查了页面的来源(因为如果浏览器解释了“
    • 这是我的代码:$url = 'w3schools.com/tags/ref_standardattributes.asp'; $ctx = stream_context_create(array('http'=> array('timeout' => 60, // 60 秒 = 1 分钟 ) )); $content = file_get_contents($url, false, $ctx); $arrTmp = explode('>',$content); for($i = 0; $i '; echo 'Res->'.($arrTmp[$i]); } 谢谢!
    • 非常感谢! :D 这就是我需要的所有东西。 :)
    猜你喜欢
    • 2012-12-24
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    • 1970-01-01
    • 2011-11-26
    • 2023-03-17
    • 1970-01-01
    • 2019-01-09
    相关资源
    最近更新 更多