【问题标题】:Only first word of title retrieved with PHP showing仅显示 PHP 检索到的标题的第一个单词
【发布时间】:2015-02-02 17:17:04
【问题描述】:

所以我试图在我的另一个网站上显示一个列表,一切正常,但只存储了“标题”属性的第一个单词。我知道整个标题是从其他网站检索到的,所以我如何让它存储所有它。

如果有帮助,这里是代码。

<?php
include "simple_html_dom.php";
$page = file_get_html("http://www.blade-edge.com/images/KSA/Flights/craft.asp?r=true&db=dunai");
echo "<table id=list>"; 
foreach($page->find('html/body/div/div[2]/ol/a') as $key=>$element) {
    if ($element->title != "No craft within this SOI"){
        $ships[$key] = $element->plaintext;
        $shipTitles[$key] = $element->title;
        $shipLinks[$key] = $element->href;
        echo "<tr>"; 
        echo "<td title =".$shipTitles[$key]." >";
        echo $ships[$key];
        echo "</td>";
        echo "</tr>";
    }
}
echo "</table>";
?>

【问题讨论】:

    标签: php html title simple-html-dom


    【解决方案1】:

    将标题放在引号内

    echo "<td title =".$shipTitles[$key]." >";   // Wrong
    

    正确的是

    echo "<td title ='".$shipTitles[$key]."' >";
    

    没有引号,你只会看到第一个空格之前的单词

    【讨论】:

    • 谢谢,已解决
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-26
    • 2014-10-21
    • 1970-01-01
    • 2022-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多