我在网站目标中得到了这种代码
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
有可能吗?
我认为您需要使用
echo $ret->outertext;
请参阅http://simplehtmldom.sourceforge.net/manual_api.htm
您需要将标志$stripRN
设置为false,默认情况下为bacause,换行标签被剥去。更改为:
$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);