Before all: My english is not that good, so... I'd like to ask for apologizes if you guys can't understand me :)
So, this is what I'm looking for: I'm being using a Wordpress plugin to generate XML (WP ALL EXPORT). Good.
Now, I need to open a file and edit some stuffs. I started with:
$data = file_get_contents("1439828483.xml");
And now I'm working using str_replace and preg_replace to update the lines I need.
I have two XML tag like these:
<cidade><![CDATA[sao-paulo>santo-andre]]></cidade>
<bairro><![CDATA[sao-paulo>santo-andre]]></bairro>
You see the content is the same... but it's because I have one ">" character splitting 2 stuff.
In the <cidade></cidade>
tag I need to keep only what is before ">".
In the <bairro></bairro>
tag I need to keep only what is after ">".
For the second problem, I fixed using this:
$data = preg_replace('#(<bairro>).*?(>)#', '$1$2', $data);
$data = str_replace('<bairro>>', "<bairro><![CDATA[",$data);
The result is:
<bairro><![CDATA[santo-andre]]></bairro>
OK, I have the content but it still have hyphens (dashes) and now I'm not able to fix it (No idea how to). What I really need is:
<bairro><![CDATA[santo andre]]></bairro>
And of course, for the tag <cidade></cidade>
I would need to have:
<cidade><![CDATA[sao paulo]]></cidade>
Before posting here, I found this topic: Regex between, from the last to specific end
But I tried to edit some parts of anubhava and Jack Maney answers but I failed :(
As I'm using preg_replace and str_replace I don't know if there is some limitations for regex strings.
Thanks and I hope you guys can understand me :D