Page 1 of 2
Help with parsing.
Posted: Mon Mar 12, 2007 3:25 pm
by 303tech
Hello, im pretty new to php/sql programming. I do understand most of it, but I cannot figure out the command for what i need done.
I have a text ini file. I want the script to browse the script looking for the line, STOREID=
But i only want whats after that such as
STOREID=Joes Shack
Joes Shack goes into a $storeid string
Problem is that there is no set length in the name, but i need all of it.
Can anyone help? thanks in advance.
Nick
Posted: Mon Mar 12, 2007 3:28 pm
by feyd
Have you tried
parse_ini_file()?
Alternately,
file() combined with a loop using
strpos() then a
substr() can extract the name.
Posted: Mon Mar 12, 2007 3:41 pm
by stereofrog
I'd use regular expressions
Code: Select all
$text = file_get_contents(YOUR-FILENAME);
preg_match_all('/STOREID=(.*)/', $text, $m);
$store_ids = $m[1];
$store_ids will contain all IDs in the source file.
Posted: Mon Mar 12, 2007 5:08 pm
by 303tech
There is only one STOREID= per ini
Posted: Mon Mar 12, 2007 5:18 pm
by 303tech
Where does it say how you can select only the word(s) in between two sets of letters. Heres an example...maybe im not following you guys or vice versa. If I only want to set ROSIES DINER into a string, how would i do this?
I'd basically be saying that i would want to copy everything after the unitname=, but before ADDRESS1=
However, this is not always in the same order....so i want to find a way to select only what is after =.
[IBERTECH]
TWENTYFIVEHOURCLOCK=TRUE
AUTOEODCLOCKOUT=TRUE
EDITCLOCKIN=TRUE
;Directories
UNITNUMBER=1171
UNITNAME=ROSIE'S DINER
ADDRESS1=
ADDRESS2=
PHONE=
;Running off of floppies?
FLOPPY=TRUE
CLOSETIME=0
OPENTIME=0600
EVENTTIME=0
;Date of Business
DOB=07 20 2006
Posted: Mon Mar 12, 2007 5:24 pm
by 303tech
stereofrog wrote:I'd use regular expressions
Code: Select all
$text = file_get_contents(YOUR-FILENAME);
preg_match_all('/STOREID=(.*)/', $text, $m);
$store_ids = $m[1];
$store_ids will contain all IDs in the source file.
@preg_match_all('/STOREID=(.*)/', $text, $m);
WHAT DO THE /'S REPRESENT? IT LOOKS LIKE THE .* MEANS EVERYTHING AFTER. IS THAT CORRECT?
Posted: Mon Mar 12, 2007 5:33 pm
by RobertGonzalez
303tech wrote:Where does it say how you can select only the word(s) in between two sets of letters. Heres an example...maybe im not following you guys or vice versa. If I only want to set ROSIES DINER into a string, how would i do this?
I'd basically be saying that i would want to copy everything after the unitname=, but before ADDRESS1=
However, this is not always in the same order....so i want to find a way to select only what is after =.
Code: Select all
[IBERTECH]
TWENTYFIVEHOURCLOCK=TRUE
AUTOEODCLOCKOUT=TRUE
EDITCLOCKIN=TRUE
;Directories
UNITNUMBER=1171
; PER THE MANUAL ALL NON ALPHA NUMERIC VALUES NEED TO BE IN DOUBLEQUOTES
UNITNAME="ROSIE'S DINER"
ADDRESS1=
ADDRESS2=
PHONE=
;Running off of floppies?
FLOPPY=TRUE
CLOSETIME=0
OPENTIME=0600
EVENTTIME=0
;Date of Business
DOB=07 20 2006
Code: Select all
<?php
$ini = parse_ini_file('myini.ini.php');
$rosies = $ini['UNITNAME'];
?>
EDIT | Damn fast submit button

Posted: Mon Mar 12, 2007 7:05 pm
by 303tech
yea but the program that reads the ini, may not like the double quotes.
Posted: Mon Mar 12, 2007 7:05 pm
by 303tech
i should say that the ini..is not for a php script. it is for a program.
Posted: Mon Mar 12, 2007 7:08 pm
by RobertGonzalez
I thought we were talking about a PHP script?

Posted: Tue Mar 13, 2007 1:17 pm
by 303tech
Sorry let me tell you a little about what im working with here. I should have been more clear.
Basically, its a Point of Sale system software that loads an ini. It is not a php script ini.
This software loads every day. It loads an html page into the workspace (which means i should be able to get it to pull dynamic content). I want to set this page to do a couple things right now.
-Parse the ini file for Storeid=, send to $sid
-search store by phone
-send the current ip of POS host machine to $ip, where it is stored on a remote db.
-mass update messages and news.
I want to be able to load the store name or number from the ini, into a variable of a php script.
The admin backend would have some type of phone number SEARCH function... which would then pull up a table of:
Phone Number, STORE Name, Ip address, and current advertisements or news.
There would also be a place within admin to post or edit news where it would then show up on the page of the software everytime its loaded.
Posted: Tue Mar 13, 2007 2:13 pm
by RobertGonzalez
Sounds like you might need a database. At least everything you want to do would be easier achieved with a database.
Posted: Wed Mar 14, 2007 12:57 am
by 303tech
Well yea, i had planned for a database. my problem is that i dont know how to select certain text after the = , but only untill pagebreak.
Do i not make any sense?
Posted: Wed Mar 14, 2007 1:28 am
by RobertGonzalez
Can you post the ini file (without breaking any rules of your own)?
Posted: Wed Mar 14, 2007 2:55 pm
by 303tech
I already posted part of it above.