DOM Selector.text()中的PHP变量赢得';不要附加到链接上

DOM Selector.text()中的PHP变量赢得';不要附加到链接上,php,wordpress,Php,Wordpress,我试图从一个div中提取文本,然后在tweet上发布它。我使用下面的方法获取文本,但当我尝试将其添加到下面的tweet链接时: <?php $include = quotescollection_quote(); $html = <<<EOF <div class="quote"> {$include} </

我试图从一个div中提取文本,然后在tweet上发布它。我使用下面的方法获取文本,但当我尝试将其添加到下面的tweet链接时:

        <?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>' ?>

如果您在将$quote传递到URL时遇到问题,请使用“urlencode”:

 <?php echo '<a href="http://twitter.com/home?status=Currently reading' . urlencode($quote) . 'from the Winifred Paper Blog!" title="Click to send this page to Twitter!" target="_blank">Tweet it</a>' ?>


您能举例说明您获得的实际输出和您想要的输出吗?从您对问题的描述中,我无法完全理解您在代码中展示的示例代码对我来说很好-您确定
$include
包含您认为它的功能吗?能否显示
var\u转储($include)?是-变量转储为空。这就是问题所在。我将运行quotescollection_quote()短代码得到的实际HTML关联为输出。我真的只需要在该div中的文本从该div中跳出后找到它。我是一个试图帮助我妻子的PHP新手。非常抱歉,我确信有一个简单的解决方案。这实际上相当简单,解决方法是-将第一行替换为
ob_start();quoteCollection_quote()$quote=ob_get_clean()并且它应该按预期工作。这基本上只是捕获由该函数创建的输出,并将其放入
$quote
变量中-有关更多信息,请参阅手册的“Dave you’s absolute god send”。它现在工作得很好。我不能告诉你我有多感激它。谢谢-这实际上似乎是我的选择器如何运行的问题,而不是我的编码问题。努力克服它-但谢谢你!