Simplehtmldom解析<pre> but got error</pre>

时间:2014-08-27 02:17:13

标签: php simple-html-dom

我在网站目标中获得了这种代码

http://lufy.byethost6.com/tes.html

使用此代码解析它

<?php 
include('simple_html_dom.php');
$html = new simple_html_dom();
$html = file_get_html('http://lufy.byethost6.com/tes.html');
$ret = $html->find('pre',0);
echo $ret;
?>

当我看到结果时,它变成了这样的一行

  title goes here    Intro : Gm Cm           Gm Cm       Gm                                  Cm  lyrics, lyrics, lyrics, lyrics, lyrics, lyrics,     Gm                   Cm  lyrics, lyrics, lyrics, lyrics, lyrics, lyrics 

我希望结果看起来像目标网站

title goes here

Intro : Gm Cm 
        Gm Cm 


Gm                                  Cm
lyrics, lyrics, lyrics, lyrics, lyrics, lyrics, 
  Gm                   Cm
lyrics, lyrics, lyrics, lyrics, lyrics, lyrics

有可能吗?

2 个答案:

答案 0 :(得分:1)

我认为你需要使用

echo $ret->outertext;

请参阅http://simplehtmldom.sourceforge.net/manual_api.htm

答案 1 :(得分:0)

您需要将标记$stripRN设置为false,默认情况下为暂停,换行符 标签被剥离。改为:

$html = file_get_html('http://lufy.byethost6.com/tes.html', $use_include_path = false, $context=null, $offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=false, $defaultBRText=DEFAULT_BR_TEXT);