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
精彩评论