Hello I have this regular expression: </book>(?:\n)<collection>(.*)</collectioninfo> And I have this peace of text on a FILE <book bookid="3" title="the title 3" remaining = "50" price="100"> <reader readerid="1"><![CDATA[John]]></reader> <reader readerid="2"><![CDATA[Michael]]></reader> <reader readerid="3"><![CDATA[Peter]]></reader> <reader readerid="4"><![CDATA[Maria]]></reader> </book> <collectioninfo id="123"> <title>colletion 1</title> <date>Jun 19 11:00</date> <type>2</type> <limit>100</limit> </collectioninfo> <book bookid="4" title="the title 4" remaining = "50" price="100"> <reader readerid="1"><![CDATA[John]]></reader> <reader readerid="2"><![CDATA[Michael]]></reader> <reader readerid="3"><![CDATA[Peter]]></reader> <reader readerid="4"><![CDATA[Maria]]></reader> </book> And i need replace the text in BOLD for: </book> So... using PHP how can I do that ... but saving the result in the same file.. I mean.. replace the current text on a file.. for the new one.. Thx.