使用';及;在php语法中
可能重复:使用';及;在php语法中,php,syntax,simplexml,php-5.2,Php,Syntax,Simplexml,Php 5.2,可能重复: 我从新年决心的一部分开始,决定学习php,作为其中的一部分,我试图在xml提要中解析,并呼应出用包装的事件名称; 回声“”; } ?> 更改 echo "<a href="$event_attributes['url']">"; echo”“; 为了 echo”“; 您缺少第二个回音中的句点,您的$event\u属性['url'] <?php foreach($type->market as $event) { echo "<l
我从新年决心的一部分开始,决定学习php,作为其中的一部分,我试图在xml提要中解析,并呼应出用
包装的事件名称;
回声“”;
}
?>
更改
echo "<a href="$event_attributes['url']">";
echo”“;
为了
echo”“;
您缺少第二个回音中的句点,您的$event\u属性['url']
<?php
foreach($type->market as $event) {
echo "<li>";
echo "<a href=".$event_attributes['url'].">";
echo $event_attributes['name'];
echo "</a>";
echo "</li>";
}
我建议您启用错误日志,它将允许您了解任何脚本中出现问题的行
echo "<a href="$event_attributes['url']">";
与
$hello ="Hello";
echo $hello.' master';
当您测试PHP脚本时,您会发现打开错误非常有用-然后PHP会告诉您为什么它没有显示任何内容:
error_reporting(E_ALL);
通常情况下,您会错过一个;
或错误地键入一个变量名
在您的情况下,错误如下:
echo "<a href="$event_attributes['url']">";
在无序列表中,应使用点连接字符串,并按如下方式转义双引号:
echo "<a href=\"".$event_attributes['url']."\">";
echo”“;
而不是
echo "<a href="$event_attributes['url']">";
echo”“;
您的示例抛出并出错,因为您没有使用正确的字符串连接。但是,即使使用正确的concat,它也会呈现为
,并且您需要根据html标准添加双引号。因此,如果您不想在使用'
或“
那么我建议使用php替代语法
对于给定的代码,它看起来像
<?php
// F1 W/H xml feed
$xml = simplexml_load_file('http://whdn.williamhill.com/pricefeed/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=5&marketSort=HH&filterBIR=N');
foreach ($xml->response->williamhill->class->type as $type) {
$type_attrib = $type->attributes();
echo "<h2>".$type_attrib['name']."</h2>"; //Title - in this case f1 championship
} ?>
<ul>
<?php foreach($type->market as $event):?>
<li>
<a href="<?php echo $event_attributes['url']; ?>">
<?php echo $event_attributes['name']; ?>
</a>
</li>
<? endforeach;?>
</ul>
-
这将带来的一个好处是,它将生成更干净的代码,因为您可以清楚地将php
代码与html
代码区分开来,后者是以编写所有其他
以及其他人声称的性能降低为代价的表示部分。您可以选择空白的PHP页面通常意味着错误。检查错误日志或在php.ini/.htaccess/.user.ini中启用启用error\u reporting
(调用脚本中的语法错误太晚了)。如何解析$event\u属性
数组?我想你甚至可以说”如果您有一个不挑剔的警告策略,代码>应该是可能的是:-)
echo "<a href="$event_attributes['url']">";
echo "<a href="
echo '<a href="' . $event_attributes['url'] . '">';
$myVar = "BLAH";
echo "Example $myVar"; // Example BLAH
echo 'Example $myVar'; // Example $myVar
echo "<a href=\"".$event_attributes['url']."\">";
echo "<a href="$event_attributes['url']">";
<?php
// F1 W/H xml feed
$xml = simplexml_load_file('http://whdn.williamhill.com/pricefeed/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=5&marketSort=HH&filterBIR=N');
foreach ($xml->response->williamhill->class->type as $type) {
$type_attrib = $type->attributes();
echo "<h2>".$type_attrib['name']."</h2>"; //Title - in this case f1 championship
} ?>
<ul>
<?php foreach($type->market as $event):?>
<li>
<a href="<?php echo $event_attributes['url']; ?>">
<?php echo $event_attributes['name']; ?>
</a>
</li>
<? endforeach;?>
</ul>