只显示使用PHP显示的标题的第一个字 [英] Only first word of title retrieved with PHP showing
本文介绍了只显示使用PHP显示的标题的第一个字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果有帮助,以下是代码。
<?php
包含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!=此SOI内没有任何工艺){
$ ships [$ key] = $ element-> plaintext;
$ shipTitles [$ key] = $ element-> title;
$ shipLinks [$ key] = $ element-> href;
回显< tr>;
echo< td title =。$ shipTitles [$ key]。>;
echo $ ships [$ key];
回声< / td>;
回声< / tr>;
}
}
echo< / table>;
?>
解决方案
将标题放在引号内
echo< td title =。$ shipTitles [$ key]。>; //错误
正确的是
echo< td title ='。$ shipTitles [$ key]。'>;
如果没有引号,您将只能看到第一个空格的单词
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>";
?>
解决方案
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
这篇关于只显示使用PHP显示的标题的第一个字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文