[thelist] placing the pointer in a text file using PHP..

Carl J Meyer cjmeyer at npcc.net
Mon Dec 30 16:06:01 CST 2002


ftruncate() always truncates the end of the file.

To chop off the beginning (afaik) you're just going to have to read it
all in, cut it down to the pieces you want, and write it back out
again.  There are several ways to do this - I'd likely just use file()
to read it into an array, then loop through the array looking for <?xml
(strstr() is easiest, preg_match() if you want more control) and don't
start writing till you find it.

I'm guessing this isn't really the best approach for your application,
though.  It would be more efficient to strip the junk from the data
before you write it to a file in the first place.  Or if you don't have
control over how the file is written, then just strip the junk when you
read it in before you do any further processing of the data, but don't
bother re-writing to the file.

In general, file operations are slow and prone to security risks, so you
should keep them to the necessary minimum.


On Mon, 2002-12-30 at 13:45, Tom Dell'Aringa wrote:
> Continuing on with my text file..its actually an XML file. I can't
> use my XML parsing script because I have the header information in my
> XML file.. I need to strip that first. Here is what I get back:
> -----------
> **** need to delete between the asterisks
> HTTP/1.1 200 OK
> Date: Mon, 30 Dec 2002 21:38:38 GMT
> Server: Apache/1.3.20 Sun Cobalt (Unix) Chili!Soft-ASP/3.6.2
> mod_jk/1.1.0 mod_ssl/2.8.4 OpenSSL/0.9.6g PHP/4.1.2
> mod_auth_pam_external/0.1 FrontPage/ mod_perl/1.25
> X-StoreSense:
> Cache-Control: no-cache
> Connection: close
> Content-Type: text/xml
> ****
> <?xml version="1.0"?>
> <XTE>
> <Response type="Product" txnid="pm01"
> timestamp="2002-12-30T21:38:38Z">
> <Outcome>Success</Outcome>
> <Product>
> <Description/>
> <ProductName>Kiddush Cup #1052</ProductName>
> <ProductNo>117</ProductNo>
> </Product>
> </Response>
> </XTE>
> ---------------
> I see that I can use fseek() to place my pointer, but how can I find
> out the place to put it correctly ..i.e., I need to find out in my
> XML file where <?xml is so I can place the pointer right before the
> opening <. Then I imainge once I place the pointer there I should be
> able to remove that data..maybe using ftruncate()?
> 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
> --
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !

More information about the thelist mailing list