I’m trying to search for data in a XML File using php.
I’m not trying to get values of certain elements, I would use xpath if I wanted that.
This is an example of my XML file:
<root>
<author>foo</author>
<date>bar</date>
</root>
Let’s say my client wants to search for the words ‘fab’.
I want all strings with the character ‘f’ and ‘b’ and ‘a’ to return.
So output would be:
Foo
bar
The author name could be James Westside for example.
<author>James Westside</author>
And the user searched for jam
it would return James Westside
I hope my question is clear.
You should use PHP:s XMLReader class. XMLReader acts as a cursor going forward on the document stream and stopping at each node on the way.
Something like this: