PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
303tech
Forum Commoner
Posts: 31 Joined: Sun Mar 11, 2007 3:25 pm
Post
by 303tech » Fri Mar 30, 2007 2:23 pm
I asked about this in another post but I must not have been clear enough with my problem.
if there is an ampersand in the ini file which i parse, the result =0
The result is correct if you take the & out of the ini file. It also has problems with apostrophes and other chars. How can around this?
I cant get it to read any further.
Code: Select all
$ini = parse_ini_file('File.ini');
$un=$ini['UNITNAME'];
Code: Select all
[IBERTECH]
TWENTYFIVEHOURCLOCK=TRUE
AUTOEODCLOCKOUT=TRUE
EDITCLOCKIN=TRUE
;Directories
UNITNUMBER=1
UNITNAME=Joe's Pizza & Pasta
ADDRESS1=6860 S. Abc Way.
ADDRESS2=Greenwood,CO 80112
[REPORT]
PRINTFULLCARD=1
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 30, 2007 3:21 pm
Tried putting double quotes around the values?
303tech
Forum Commoner
Posts: 31 Joined: Sun Mar 11, 2007 3:25 pm
Post
by 303tech » Fri Mar 30, 2007 4:43 pm
in the parse_ini_file()? using "file.ini" instead of 'file.ini' ?
the INI is NOT able to change. the php must work around it.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 30, 2007 4:51 pm
Then I think you'll need to parse it yourself.
303tech
Forum Commoner
Posts: 31 Joined: Sun Mar 11, 2007 3:25 pm
Post
by 303tech » Fri Mar 30, 2007 6:19 pm
then how about using something like.
Code: Select all
<?php
$contents = file("File.ini");
$pos=strpos($contents, "UNITNAME=");
$string=substr($contents, $pos, 40);
$pos2=strpos($string, "=");
echo substr($string, 9, 25);
?>
Problem is, some names are only five letters so then it will take the next line of INI into the string. How could I use regex to to only copy from position 9 till = \n (untill it reaches a space).
stereofrog
Forum Contributor
Posts: 386 Joined: Mon Dec 04, 2006 6:10 am
Post
by stereofrog » Fri Mar 30, 2007 6:37 pm
how about
Code: Select all
$ini = array();
foreach(file($ini_file) as $line)
if(preg_match('/^([^;].*?)\s*=\s*(.*)/', trim($line), $m))
$ini[$m[1]] = $m[2];
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Fri Mar 30, 2007 7:34 pm
I too was thinking regex - but you'll have to do it in multiple dimensions so you don't overwrite values from previous sections.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 30, 2007 11:11 pm
After stripping the line of any comment and determining that it is not a section specifier
explode() would work well, actually.