开发者

Use of undefined constant caused by dash?

This works

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

But this does not

$source = simplexml_load_file('da开发者_开发百科ta.xml');
foreach ($source->programme as $programme) {
  echo $programme->sub-title . "<br />";
}

I get this error :

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

This error is likely caused by the use of "-" in second code snippet.

My question is: Can I escape the dash character and make this work?


Follow this way:

$programme->{'sub-title'}

This trick is even described in basic simplexml usage section

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜