Help with parsing.

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

Help with parsing.

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have you tried parse_ini_file()?

Alternately, file() combined with a loop using strpos() then a substr() can extract the name.
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post 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.
303tech
Forum Commoner
Posts: 31
Joined: Sun Mar 11, 2007 3:25 pm

Post by 303tech »

There is only one STOREID= per ini
303tech
Forum Commoner
Posts: 31
Joined: Sun Mar 11, 2007 3:25 pm

Post 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
303tech
Forum Commoner
Posts: 31
Joined: Sun Mar 11, 2007 3:25 pm

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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 :oops:
303tech
Forum Commoner
Posts: 31
Joined: Sun Mar 11, 2007 3:25 pm

Post by 303tech »

yea but the program that reads the ini, may not like the double quotes.
303tech
Forum Commoner
Posts: 31
Joined: Sun Mar 11, 2007 3:25 pm

Post by 303tech »

i should say that the ini..is not for a php script. it is for a program.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I thought we were talking about a PHP script? :?
303tech
Forum Commoner
Posts: 31
Joined: Sun Mar 11, 2007 3:25 pm

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sounds like you might need a database. At least everything you want to do would be easier achieved with a database.
303tech
Forum Commoner
Posts: 31
Joined: Sun Mar 11, 2007 3:25 pm

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Can you post the ini file (without breaking any rules of your own)?
303tech
Forum Commoner
Posts: 31
Joined: Sun Mar 11, 2007 3:25 pm

Post by 303tech »

I already posted part of it above.
Post Reply