I am using PHP to cleanup some Strings coming from Flash.
I get some code like this
<CONTENT><![CDATA[<P alight="left">sometext</P><P alight="left">moretest</P><P>yet more text</P>]]></CONTENT>
BUT
I want it to look like this
<CONTENT><![CDATA[<P alight="left">sometext</P><P alight="left">moretest</P><TEXTFORMAT>yet more text</TEXTFORMAT >]]></CONTENT>
I want the last two instances of P to read TEXTFORMAT. If I use php to do something like this:
$XML = preg_replace("/\<P(.+?)\<\/P\>\]\]\>\<\/CONTENT\>/", "<TEXTFORMAT $1</TEXTFORMAT>]]></CONTENT>", $RAWXML);
It replaces the first instance of P and the last, but I want it to replace the last and the one before that.
Also, the numbe of paragraphs always changes, the actual raw code is like this:
<?xml version="1.0" encoding="ISO-8859-1"?><ENTRIES><ENTRY><TITLE>Post1</TITLE><CONTENT><![CDATA[<P ALIGN="LEFT"><FONT FACE="Optima" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">I have used Shredit X for quite a while. It is most useful for cleaning up hard drives. The shredding of free space is invaluable. The reviewers who only dwell on file removal haven't done their homework. (8/30/2004, Version: 5.5.1)</FONT></P>]]></CONTENT></ENTRY><ENTRY><TITLE>Post2</TITLE><CONTENT><![CDATA[<P ALIGN="LEFT"><FONT FACE="Optima" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">I have used Shredit X for quite a while. It is most useful for cdtyrft 5.5.1)</FONT></P>]]></CONTENT></ENTRY><ENTRY><TITLE>Post3</TITLE><CONTENT><![CDATA[<P ALIGN="LEFT"><FONT FACE="Optima" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">I have used Shredit X for quite a while. It is most useful for cleaning up hard drives. The shredding of free space is invaluable. The reviewers who only dwell on file removal haven't done their homework. (8/30/2004, Version: 5.5.1)</FONT></P>]]></CONTENT></ENTRY><ENTRY><TITLE>Post4</TITLE><CONTENT><![CDATA[<P ALIGN="LEFT"><FONT FACE="Optima" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">this is just great!!</FONT></P>]]></CONTENT></ENTRY><ENTRY><TITLE>Post5</TITLE><CONTENT><![CDATA[<P ALIGN="LEFT"><FONT FACE="Optima" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">I have used Shredit X for quite a while. It is most useful for cleaning up hard drives. The shredding of free space is invaluable. The reviewers who only dwell on file removal haven't done their homework. (8/30/2004, Version: 5.5.1)</FONT></P>]]></CONTENT></ENTRY><ENTRY><TITLE>Post6</TITLE><CONTENT><![CDATA[<P ALIGN="LEFT"><FONT FACE="Optima" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="0">I have used Shredit X for quite a while. It is most useful for cleaning up hard drives. The shredding of free space is invaluable. The reviewers who only dwell on file removal haven't done their homework. (8/30/2004, Version: 5.5.1)</FONT></P>]]></CONTENT></ENTRY></ENTRIES>
I am not very experienced with PHP so I'm hoping someone can help me out.