带有引号的DOMDocument在加载URL中

时间:2014-02-16 21:39:42

标签: php wordpress domdocument

我正在使用domdocument显示来自Wordpress的搜索URL的XML文件的内容。一切都在正常的搜索网址上运行,但是当我希望搜索与短语的“完全匹配”时,这意味着我必须在关键短语周围加上双引号,它什么也不返回。那么如何在添加引用时让它工作,如下面的URL所示......

    $rss = new DOMDocument();
$rss->load('' . home_url() . '/?s="' . ucfirst($player_data->first_name) . '+' . ucfirst($player_data->last_name) .  '"&post_type=post&feed=rss2');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
    $item = array ( 
        'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
        'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
        'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
        'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
        );
    array_push($feed, $item);
}
//foreach($item as $moment); {
if (!$item==NULL) {
for($x=0;$x<10;$x++) {
    $woohoo = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
    $goto = $feed[$x]['link'];
    $timex = $feed[$x]['desc'];
    $dibidy = date('l F d, Y', strtotime($feed[$x]['date']));
    $str_view_player .=  '<div><strong><a href="'.$goto.'">'.$woohoo.'</a></strong></div>';
    // $str_view_player .=  '<small><em>Posted on '.$dibidy.'</em></small></p>';
    // $str_view_player .=  '<p>'.$timex.'</p>';
} 
    } else {
    $str_view_player .=  '' . ucfirst($player_data->first_name) . ' ' . ucfirst($player_data->last_name) .  ' has not been mentioned yet - but he will soon, we are sure of it!';
    }

注意s =之后和&amp; post_type

之后的引号

1 个答案:

答案 0 :(得分:0)

使用%22替换您的引号或使用urlencode()

$url = '' . home_url() . '/?s="' . ucfirst($player_data->first_name) . '+' . ucfirst($player_data->last_name) .  '"&post_type=post&feed=rss2';
$url = urlencode($url);
$rss->load($url);