gpt4 book ai didi

php - 使用破折号引起的未定义常量?

转载 作者:可可西里 更新时间:2023-11-01 00:17:04 26 4
gpt4 key购买 nike

这行得通

$source = simplexml_load_file('data.xml');
foreach ($source->programme as $programme) {
echo $programme->title . "<br />";
}

但这不

$source = simplexml_load_file('data.xml');
foreach ($source->programme as $programme) {
echo $programme->sub-title . "<br />";
}

我收到这个错误:

"Notice: Use of undefined constant title - assumed 'title' in ..."

此错误可能是由于在第二个代码片段中使用“-”引起的。

我的问题是:我可以转义破折号字符并使其正常工作吗?

最佳答案

按照这种方式:

$programme->{'sub-title'}

这个技巧甚至在 basic simplexml usage 中有描述。节

关于php - 使用破折号引起的未定义常量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5447923/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com