I need to search and rewrite specific lines in xml file with PHP. I have this xml structure:
<contentList>
<content contentuid="h0001d8b9g13d6g4605g85e9g708fe1e537c8">2p_some text.</content>
<content contentuid="h000824a4gf6cfg4e7cgad12g3cf2b4473efe">some text.</content>
<content contentuid="h000824a4gf6cfg4e7cgad12g3cf2b4473efe">some text.</content>
<content contentuid="h0001d8b9g13d6g4605g85e9g708fe1e537c8">10txp_some text</content>
<content contentuid="h000824a4gf6cfg4e7cgad12g3cf2b4473efe">15t_some text.</content>
</contentList>
I need to search lines with _ symbol inside the tags and rewrite numbers (2p, 4t...) with number of the line, but the letters after the number and _ must remain. Lines without _ symbol remain unchanged.
So it should look like this:
<contentList>
<content contentuid="h0001d8b9g13d6g4605g85e9g708fe1e537c8">1p_some text.</content>
<content contentuid="h000824a4gf6cfg4e7cgad12g3cf2b4473efe">some text.</content>
<content contentuid="h000824a4gf6cfg4e7cgad12g3cf2b4473efe">some text.</content>
<content contentuid="h0001d8b9g13d6g4605g85e9g708fe1e537c8">4txp_some text</content>
<content contentuid="h000824a4gf6cfg4e7cgad12g3cf2b4473efe">5t_some text.</content>
</contentList>
It is possible? I'm really bad at XML parsing :D Any help will be appreciated. Thanks
No comments:
Post a Comment