RE: [PHP] Regular expression help converting doc to xml (somewhat OT)
| From: | Geoff | Date: | Mon, 30 Sep 2002 14:06:16 +0000 |
| Subject: | RE: [PHP] Regular expression help converting doc to xml (somewhat OT) | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-118205@lists.php.net to get a copy of this message | ||
On Fri, 2002-09-27 at 16:53, John Holmes wrote:
This isn't accurate enough because <DT> is not always preceeded by:
<DD> some text. It is sometimes preceeded by <DT> some text </DT> or
other items.
This expression matches fairly well:
<DD>[a-zA-Z0-9\.,'\-\s]*
So it matches up to the <DT>:
<DD> A whole bunch of text
<DT> Something else </DT>
But I don't know how to do the replace part.
So essentially I need find this:
<DD> A whole bunch of text
and replace it with this:
<DD> A whole bunch of text </DD>
>
> $new_text =
> str_replace("\n\t<DT>","</DD>\n\t<DT>",$your_text);
>
> Assuming there is a tab in there...
>
> You'd be better off getting an editor that'll do this for you. Textpad
> lets you search and replace with regular expressions. Other programs do
> too.
>
> ---John Holmes...
>
> > I have a fairly large html document that I need to convert to xml.
> > The current format is is:
> > <DD> A whole bunch of text
> > <DT> Something else </DT>
> > (There is a new line in there before <DT>)
> >
> > Which I need to convert to
> > <DD> A whole bunch of text </DD>
> > <DT> Something else </DT>