我正在尝试将文本从 div 中提取出来,然后发布推文。我正在使用以下方法获取文本,但是当我尝试将其添加到下面的推文链接时:
<?php
$include = quotescollection_quote();
$html = <<<EOF
<div class="quote">
{$include}
</div>
EOF;
// create a document object from your html string
$doc = new DOMDocument();
$doc->loadHTML($html);
// create a xpath selector for the document
$selector = new DOMXPath($doc);
// use xpath query to access the text of <q> node
$quote = $selector
->query('//div[@class="quote"]/div/p/q/text()')
->item(0)
->nodeValue;
?>
<?php echo '<a href="http://twitter.com/home?status=Currently reading' . $quote . 'from the Winifred Paper Blog!" title="Click to send this page to Twitter!" target="_blank">Tweet it</a>' ?>
输出当前是引用变量的内容,作为断开链接的文本。先感谢您!