Help with parsing.
Moderator: General Moderators
Help with parsing.
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
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
- stereofrog
- Forum Contributor
- Posts: 386
- Joined: Mon Dec 04, 2006 6:10 am
I'd use regular expressions
$store_ids will contain all IDs in the source file.
Code: Select all
$text = file_get_contents(YOUR-FILENAME);
preg_match_all('/STOREID=(.*)/', $text, $m);
$store_ids = $m[1];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
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
@preg_match_all('/STOREID=(.*)/', $text, $m);stereofrog wrote:I'd use regular expressions$store_ids will contain all IDs in the source file.Code: Select all
$text = file_get_contents(YOUR-FILENAME); preg_match_all('/STOREID=(.*)/', $text, $m); $store_ids = $m[1];
WHAT DO THE /'S REPRESENT? IT LOOKS LIKE THE .* MEANS EVERYTHING AFTER. IS THAT CORRECT?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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'];
?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.
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.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA