Only first word of title retrieved with PHP showing

☆樱花仙子☆ 提交于 2019-12-30 07:27:12

问题


So I am trying to display a list from another website in mine, it all works fine but only the first word of the 'title' attribute is stored. I know that the whole title is retrieved from the other website so how do I get it to store all of it.

Here is the code if it helps.

<?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>";
?>


回答1:


Put title inside quotation marks

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

Right is

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

Without quotes, you will only see the word till the first space



来源:https://stackoverflow.com/questions/28283104/only-first-word-of-title-retrieved-with-php-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!