0

HTML 源代码:

<div id="ctl00_ContentPlaceHolder_Middle_RatingSummary1_Rating1_RatingPanel">
<img id="ctl00_ContentPlaceHolder_Middle_RatingSummary1_Rating1_RatingImage" title="(2.5 / 5)  : Above Average" src="../../../../../images/net/common/stars/transparent/2.5.png" alt="(2.5 / 5)  : Above Average" style="border-width:0px;" />
<span id="ctl00_ContentPlaceHolder_Middle_RatingSummary1_Rating1_RatingText" class="text med strong">(2.5 / 5)  : Above Average</span>
<a id="ctl00_ContentPlaceHolder_Middle_RatingSummary1_Rating1_RatingHelp" class="help"></a>

我想要这样的输出:

(2.5 / 5)  : Above Average

我试过了,但没有得到它:

php代码:

$ratings = $html->find('div[id=ctl00_ContentPlaceHolder_Middle_RatingSummary1_Rating1_RatingPanel] span')->outertext;

echo "$ratings[0]"; 
4

1 回答 1

1

首先,如果你写

echo "something_here"

你会得到作为输出

something_here

即使something_here是一个变量。如果你想打印一个变量,不要把它放在里面""

现在,而不是

$ratings = $html->find('div[id=...] span')->outertext;
echo "$ratings[0]";

尝试做

$ratings = $html->find('div[id=...] span');
echo $ratings[0]->outertext;

此外,您可能想要innertext而不是outertext

于 2013-08-24T19:33:05.993 回答