let's say I have an xml file
how do I read a specific tag (and all the values contained in that tag) of that xml file without using any sort of php library, with just straight PHP file read and string searching. Is that possible?
Thanks in advance
let's say I have an xml file
how do I read a specific tag (and all the values contained in that tag) of that xml file without using any sort of php library, with just straight PHP file read and string searching. Is that possible?
Thanks in advance
If you were looking for a tag X, you could use string searching for <X>
and </X>
. But:
<X>
shouldn't pair up with the first </X>
)Why can't you use a library?
You can use regular expressions if the tag you are searching for contain only simple text. If you want only the first occurrence:
$matches = array();
$ret = preg_match('/<yourtag>(.*?)<\\/yourtag>/i', file_get_contents('your.xml'), $matches);
if ($ret) { /* Check for $matches[1] */ }
Or multiple occurrences:
$matches = array();
$ret = preg_match_all('/<yourtag>(.*?)<\\/yourtag>/i', file_get_contents('your.xml'), $matches);
if ($ret) { /* Check for $matches[1] */ }