Home >Backend Development >PHP Tutorial >How to Access XML Node Names with Hyphens in PHP?
Accessing XML Node Names with Hyphens Using PHP
When attempting to extract data from XML, you may encounter an error when the node names contain hyphens. This error occurs because PHP's naming conventions do not allow hyphens in variable names.
To address this issue, PHP provides a way to encapsulate the element name within braces and apostrophes. This allows access to node names with hyphens.
Code Example:
<code class="php">$xml->{'custom-field-value'} // Accesses the 'custom-field-value' node with a hyphen</code>
By following this convention, you can effectively extract data from XML nodes with hyphens without encountering errors in PHP.
The above is the detailed content of How to Access XML Node Names with Hyphens in PHP?. For more information, please follow other related articles on the PHP Chinese website!