[PHP] reg ex help

2005-11-04 Thread conditional motion
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.

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



Re: [PHP] reg ex help

2005-11-04 Thread conditional motion
The problem with that is there are about 40 different listings in the
one field.

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

being three of them so maybe this is a bettter way of listing it

... Silver Small Corp;X^%\n#\nGold Medium
Corp;RE^%\n#\nPlatinum Large Corp;YRE^%\n#\n
...

On 11/4/05, Jay Blanchard [EMAIL PROTECTED] wrote:
 [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]

 You couuld use explode

 $myField = Silver Small Corp;X^%\n#\n;

 $foo = explode(;, $myField);

 echo $foo[0];


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



Re: [PHP] reg ex help

2005-11-04 Thread conditional motion
Here is what the field content from the database would look like.  I
have removed any sensitive data.

str = Name;Grill Transom (GT302)^% -
Sort;Find/Replace^% - Calc;2568.09x^% -
Type;Veck^% - PO Number;^% - Previous Order
Number;^% - Fabric Whole;Dyna-Dry^% - Fabric
Body;^% - Fabric Yoke;^% - Fabric
Sleeves;^% - Fabric Panels;^% -
ID;32398^%^%^%^%^% -
Size;6.0^%^%^%^%^% -
Layer;0^%^%^%^%^% -
Coords;147^173^400^%^^^%^^^%^^^%^^^%
- ID;%32400^%^%%%^%
- 
Coords;%147^110^400^%^^^%%%^^^%
- Back Number
Font;%Athletic^Athletic^%
- Front Text
ID;%%32402^%32403^%^%^%^%^%^%
- Roch Small Sum;0^% - Cards Med Extra;0^%
- Roch Large Sum;0^% - Silver Small Corp;X^%
- Gold Medium Corp;RE^% - Platinum Large
Corp;YRE^%;

That is one field.

On 11/4/05, Pablo Gosse [EMAIL PROTECTED] wrote:
 [snip]
 The problem with that is there are about 40 different listings in the
 one field.

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

 being three of them so maybe this is a bettter way of listing it

 ... Silver Small Corp;X^%\n#\nGold Medium
 Corp;RE^%\n#\nPlatinum Large Corp;YRE^%\n#\n
 ...[/snip]

 Try this:

 $values = array(); // we'll put the extracted vars here
 $str = This is supposed to be your string;

 $tmpStr = explode(#\n, $str);

 foreach ($tmpStr as $foo) {
if (strlen(trim($foo))  0) {
array_push($values, substr($foo, 0, strpos($foo, ';')));

}
 }

 HTH,

 Pablo

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



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



Re: [PHP] reg ex help

2005-11-04 Thread conditional motion
The name like Roch Small Sum and others dont change, they will be in
there whether there is a value associated with them or not.


On 11/4/05, conditional motion [EMAIL PROTECTED] wrote:
 Here is what the field content from the database would look like.  I
 have removed any sensitive data.

 str = Name;Grill Transom (GT302)^% -
 Sort;Find/Replace^% - Calc;2568.09x^% -
 Type;Veck^% - PO Number;^% - Previous Order
 Number;^% - Fabric Whole;Dyna-Dry^% - Fabric
 Body;^% - Fabric Yoke;^% - Fabric
 Sleeves;^% - Fabric Panels;^% -
 ID;32398^%^%^%^%^% -
 Size;6.0^%^%^%^%^% -
 Layer;0^%^%^%^%^% -
 Coords;147^173^400^%^^^%^^^%^^^%^^^%
 - ID;%32400^%^%%%^%
 - 
 Coords;%147^110^400^%^^^%%%^^^%
 - Back Number
 Font;%Athletic^Athletic^%
 - Front Text
 ID;%%32402^%32403^%^%^%^%^%^%
 - Roch Small Sum;0^% - Cards Med Extra;0^%
 - Roch Large Sum;0^% - Silver Small Corp;X^%
 - Gold Medium Corp;RE^% - Platinum Large
 Corp;YRE^%;

 That is one field.

 On 11/4/05, Pablo Gosse [EMAIL PROTECTED] wrote:
  [snip]
  The problem with that is there are about 40 different listings in the
  one field.
 
  Silver Small Corp;X^%\n#\n
  Gold Medium Corp;RE^%\n#\n
  Platinum Large Corp;YRE^%\n#\n
 
  being three of them so maybe this is a bettter way of listing it
 
  ... Silver Small Corp;X^%\n#\nGold Medium
  Corp;RE^%\n#\nPlatinum Large Corp;YRE^%\n#\n
  ...[/snip]
 
  Try this:
 
  $values = array(); // we'll put the extracted vars here
  $str = This is supposed to be your string;
 
  $tmpStr = explode(#\n, $str);
 
  foreach ($tmpStr as $foo) {
 if (strlen(trim($foo))  0) {
 array_push($values, substr($foo, 0, strpos($foo, ';')));
 
 }
  }
 
  HTH,
 
  Pablo
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 


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