Re: pulling text from a file

From: Date: Sun, 23 Mar 2008 01:29:44 +0000
Subject: Re: pulling text from a file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-271998@lists.php.net to get a copy of this message
Richard Kurth wrote:
I have a text file that looks like the one below. I need to read the file into a database. I was trying the script below but is not working can you help? $lines = file_get_contents('clientlist1.txt'); $find="Address:"; $f= strstr($f,$find); $separat="City:"; $ADDRESS = substr($f, 0, strpos($f,$separat)); $ADDRESS=ltrim($ADDRESS,"Address:"); $ADDRESS=trim($ADDRESS); echo $ADDRESS; echo "<br>"; $find="City:"; $f= strstr($f,$find); $separat="State:"; $CITY = substr($f, 0, strpos($f,$separat)); $CITY=ltrim($CITY,"City:"); $CITY=trim($CITY); echo $CITY; echo "<br>"; Text File
Address:      5070 myaddress.
City:     mycity     State:     mystate    Zip:     97268
County:    Signers
Name:     my name
Address:      3925 myaddress.
City:     mycity2     State:     mystate2     Zip:     97268
County:    Signers
Name:     my name2
If the place where you run this script has PHP > 5.1 installed, then you could use SimpleXML for this purpose. If the document MUST be in XML format. I don't know such methods in PHP 4, etc. On my server, I have PHP 5.2.5

« previous php.general (#271998) next »