[thelist] php regexp help (or some other solution maybe..)

Tom Dell'Aringa pixelmech at yahoo.com
Tue Dec 31 13:59:01 CST 2002


--- Kelly Hallman <khallman at wrack.org> wrote:
> On Tue, 31 Dec 2002, Tom Dell'Aringa wrote:
> > --- Kelly Hallman <khallman at wrack.org> wrote:
> > > This regex uses a positive lookahead:
> > > list($head,$body) = preg_split("/(?=<\?xml)/m",$inputdata,2);
> >
> > Sorry if this is a stupid question, but how do I use it (i really
> > have no understanding of regex at all) within this code block:
>
> Well, using the above line of code, $inputdata is your entire file
> and
> afterward $body contains the data you want.  Hence, yesterday's
> code:
>
> list($head,$body) =
>         preg_split("/(?=<\?xml)/m",join("",file("dump.xml")),2);

At this point I don't have a file. Per your question below, what I
have is a response from a proprietary DB from an XML query to it. I
was dumping this response into a file (dump.xml), but the header info
in the file was of course causing problems (its not a valid XML file
with the header junk in there).

Several folks suggested taking care of the header BEFORE I dump it
into my file, so I don't have to mess with it later, which makes
sense.

So at this point I have the returned data to me in a variable called
$response. How can I use your line of code with that variable instead
of a file? (Or, is it possible).. THEN I want to write the corrected
response into my dump file, where my XML Parsing code can take care
of it with (hopefully) no problem.

I do have a recent version of PHP too, 4.1.2.


> For fun, (I was going to post this to the list but I wasn't sure if
> it
> actually applied) our holiday card is here:
> http://wrackmedia.com/holiday/
> The songs and list of songs are stored in XML format and grabbed
> dynamically from the server by the Flash movie.

Very cool!

Tom

=====
var me = tom.pixelmech.webDeveloper();

http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com



More information about the thelist mailing list