|
Posted by AnrDaemon on 12/03/07 12:24
Greetings, ofuuzo1@yahoo.no.
In reply to Your message dated Monday, December 3, 2007, 11:14:21,
>> > I am new to php. I have text files each containing some metadata. I
>> > would like to use preg_replace to remove some of the fields in each
>> > text file. Some contents of a field can go over several lines. How can
>> > I do it using preg_replace?
>>
>> > <?xml version="1.0" encoding="utf-8" standalone="no" ?>
>> > <dublin_core schema="dc">
>> > <dcvalue element="contributor" qualifier="advisor">Test, Testman
>> > several lines several lines several lines several lines several
>> > lines several lines several lines several lines several lines
>> > several lines several lines several lines several lines </
>> > dcvalue>
>> > <dcvalue element="date" qualifier="issued">2007-11-15</dcvalue>
>> > <dcvalue element="format" qualifier="extent">4869077 bytes</
>> > dcvalue>
>> > <dcvalue element="format" qualifier="mimetype">application/pdf</
>> > dcvalue>
>> > <dcvalue element="language" qualifier="iso">nob</dcvalue>
>> > <dcvalue element="subject" qualifier="courseID">NOR-3920</dcvalue>
>> > <dcvalue element="subject" qualifier="departmentID">6640</dcvalue>
>> > </dublin_core>
>>
>> This isn't just text, it's XML. You really get a benefit from using one of
>> the several possibilities/extentions mentioned in the manual. DOMXML would
>> be my choice for this: <http://www.php.net/domxml>
>>
>> If you really want it using a regex (which is possible, but inflexible and
>> cumbersome), please inform us which field you want the have removed.
> I would like to use a regex. I want to open the file, remove a fix
> number of fields and its contents and store it back to the file.
> Example, removing the following:
> <dcvalue element="format" qualifier="extent">4869077 bytes</dcvalue>
> <dcvalue element="language" qualifier="iso">nob</dcvalue>
> <dcvalue element="subject" qualifier="courseID">NOR-3920</dcvalue>
> <dcvalue element="subject" qualifier="departmentID">6640</dcvalue>
Rik was right, it is NOT a plain text for what RegEx is intended.
It IS XML document, so if You want to be right you should use XML functions to
deal with it. Of course, You MAY use RegEx on any type of strings (even
binary, but results are depends on Your knowledge).
--
Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru>
Navigation:
[Reply to this message]
|