RE: reg ex help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[snip]
New to php so please bear with me.  I'm trying to parse through a field
that has some information in it, the information is stored with other
information and is delimited in a certain pattern so I figure using reg
ex I can get the information I want out of the text.

So here is an example.

Silver Small Corp;;;;;X^%%%%%\n#####\n
Gold Medium Corp;;;;;RE^%%%%%\n#####\n
Platinum Large Corp;;;;;YRE^%%%%%\n#####\n

Reall all I need is the information on Silver Small Corp, etc and the X
all the rest is gibberish.  Is Reg Ex the best way to do this or would
it be some other way.[/snip]

If the number of semi-colons is fixed, then explode will do the trick.

$foo = 'Silver Small Corp;;;;;X^%%%%%\n#####\n'; $bar = explode(';;;;;',
$foo); echo $bar[0];

However if the number of semi-colons is not fixed, then substr in
conjunction with strpos will do the trick.

$foo = 'Silver Small Corp;;;;;X^%%%%%\n#####\n'; $bar = substr($foo, 0,
strpos($foo, ';')); echo $bar;

HTH,

Pablo

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux