Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
简单的html dom php和纯文本中的新行_Php_Newline_Simple Html Dom - Fatal编程技术网

简单的html dom php和纯文本中的新行

简单的html dom php和纯文本中的新行,php,newline,simple-html-dom,Php,Newline,Simple Html Dom,当我解析一个站点并打印出纯文本时,我在打印输出中得到了很多不能通过str_替换删除的换行符 例如,如果我解析eBay并查找结束时间 $ebayEndTime = $this->html_simple_dom->find( 'span[class=vi-tm-left]', 0 )->plaintext; 在打印输出中,它如下所示: \t\t\t\t\t(2013年3月19日\n\t\t\t\t\t15:10:11 PDT)\n\t\t\t 尝试删除它无效: $search =

当我解析一个站点并打印出纯文本时,我在打印输出中得到了很多不能通过str_替换删除的换行符

例如,如果我解析eBay并查找结束时间

$ebayEndTime = $this->html_simple_dom->find( 'span[class=vi-tm-left]', 0 )->plaintext;
在打印输出中,它如下所示:

\t\t\t\t\t(2013年3月19日\n\t\t\t\t\t15:10:11 PDT)\n\t\t\t

尝试删除它无效:

$search = array('\n', '\t', '\r');
error_log("end time:" .  str_replace( $search, " ", $ebayEndTime));
仍然导致:

\t\t\t\t\t(2013年3月19日\n\t\t\t\t\t15:10:11 PDT)\n\t\t\t

要删除换行符/选项卡,我需要做什么?我甚至尝试过这样做来彻底:

$search = array('\n', '\t', '\r', '\\n', '\\t', '\\r', '\\\\n', '\\\t', '\\\r', '\\\\n', '\\\\t', '\\\\r');
据我所知,Java要求转义字符,但当它在日志文件中打印时,是否使用“\”的html代码将其打印出来?

如何:

$str = "\t\t\t\t\t(Mar 19, 2013\n\t\t\t\t\t15:10:11 PDT)\n\t\t\t";
echo trim(preg_replace('/\s+/', ' ', $str));
#=>(Mar 19, 2013 15:10:11 PDT)

我确实尝试了nl2br(),因为这是我还没有尝试过的东西,但它也不起作用,它似乎是用特殊字符打印出来的-否则,我相信我的str_replace调用会修复它。如果我用换行符/制表符在字符串中复制和过去,并通过str_replace调用运行它,那么它似乎是使用特殊字符打印出来的。这回答了这个问题……那么为什么str_replace没有这样做呢?它真的需要正则表达式吗?问题是单引号字符串是按字面意思处理的。你需要双引号来插值。这会有用的,所以我接受。这不是我想做的——我想做些更有活力的事情;-)