Parsing a file with # comment characters

From: Date: Tue, 12 Dec 2000 02:21:50 +0000
Subject: Parsing a file with # comment characters
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-29791@lists.php.net to get a copy of this message
Have a file (unix) # this is the file some stuff some other stuff #Section I want# #item# item header item descript #item# item header item descript #section I want# trailing stuff other items What I wasnt to do is open and parse the file to assign portion of it to variable... I think that PHp is choking on the comment characters contained in the strings though... here is the code: <? $avhFile="/filelocation/file.name"; $avhfp = fopen($avhFile, "r"); #read start at beginning $avhConf = fread($avhfp, filesize($avhFile)); fclose($avhfp); $avhStr = '#Section I want#'; $avhStr2 = '#item#'; $avhPieces = explode($avhStr, $avhConf); $avhFirst=$avhPieces[0],'#Section I want#'; $avhItem=explode($avhStr2, $avhPieces[1]); $avhLast='#Section I want#'.$avhPieces[2]; $avhCount=count($avhItem); echo 'There are ' . $avhCount . ' Items<br>'; $count=0; while($count<$avhCount) { $count++; echo '<b>Start Item #' . $count . '</b><br>'; echo "<pre>$avhItem[$count]</pre>"; echo '<b>End Item #' . $count . '</b><br>'; } ?> the result currently spits out: There are 1 Items Start Item #1 End Item #1 Been playing with this for a bit with no luck. The idea is to be able to rip the entire text file apart to the first part, last part, and all the items so that when we are done, we can rebuild and write back into the file. Any insight would be appreciated. Dave

« previous php.general (#29791) next »