1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

search and replace over a file

Discussion in 'PHP' started by dirdamalah, Jun 20, 2008.

  1. dirdamalah

    dirdamalah New Member

    Joined:
    Jun 20, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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.
     

Share This Page