Hi,
I need to read data from a text files which are in an xml format .
I use (in the mean time) preg match to check out every line on the file and get the data I need.
this is a typical sample:
<tagname name="name" status="status" value="value" bla bla>someText</tagname>
what I need is the name ,status and value.
The problem is not all the tags has the format and value can come before status or any other order.
this is the preg_math command I use:
if(preg_match("/name=\"([^\"]*)\"\s+status=\"([^\"]*)\"\s+value=\"([^\"]*)\"\s|name=\"([^\"]*)\"\s+value=\"([^\"]*)\"\s+status=\"([^\"]*)\"*/",$temp,$match)
it doesn't seem to make the job+in the array match I only get the data if it matches the first option(before the "|")
any solutions?
Thanks
preg_match
Moderator: General Moderators
if(preg_match('|</?sometag[^>]*?>|i', $text)){
$name=preg_grep('/name="([^"]*?)/', $text);
$status=preg_grep('/status="([^"]*?)/', $text);
$value=preg_grep('/value="([^"]*?)/', $text);
}
this will only go for the matching IF there's a tag. anything that's empty will either be null or an empty string.
this wont be order dependant, meaning that they can have name last and it will still work.
$name=preg_grep('/name="([^"]*?)/', $text);
$status=preg_grep('/status="([^"]*?)/', $text);
$value=preg_grep('/value="([^"]*?)/', $text);
}
this will only go for the matching IF there's a tag. anything that's empty will either be null or an empty string.
this wont be order dependant, meaning that they can have name last and it will still work.