Re: [PHP-DB] String question

2004-12-14 Thread Jochem Maas
Chris Payne wrote:
Hi there everyone,
 

I am having to read a string with text in, but the way the DB is written in
the same string you have the price, for example
this doesn't sound like a DB problem, sounds more like a regexp problem.
(i.e. php-db is probably the wrong list)
 

CASARON 4G
50lb Sacks in Ton Lots
$88.00
 

How can I strip out the 88.00 (Baring in mind it could be any number)  into
its own string?
http://nl2.php.net/manual/en/ref.pcre.php
NB: note the difference between using single and double quotes when
defining your regexp. e.g:
$regexp = '/^.*\$[ \t]?([0-9]+\.[0-9]{2})$/s';
and:
$regexp = /^.*\$[ \t]?([0-9]+\.[0-9]{2})$/s;
...are not the same.
assuming that the price is at the end of the string you and is preceeded 
by a dollar sign (with or without a seperating space) could do:

?php
$myString = 
CASARON 4G
50lb Sacks in Ton Lots
$88.00
\r\n
\t\r\n
;
$matches = array();
$found = preg_match(
   '/^.*\$[ \t]?([0-9]+\.[0-9]{2})$/s',
   /* some commented out alternatives */
   // '/^.*\$([0-9]+\.[0-9]{2})$/s',
   // '/^.*\$([0-9]+\.00)$/s',
   // '/^.*\$(88\.00)$/s',
   // '/.*\$(\d+\.\d+)/s',
   trim($myString), /* make life easier have a trim */
   $matches /* passed by ref */
   );
print_r(original string:\n--\n$myString);
print_r(\n\ntrimmed string:\n--\n.trim($myString).\n\n);
print_r(found: $found\n matches array contents:\n\n);
print_r($matches);
?
 

Thank you.
 

Chris
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.816 / Virus Database: 554 - Release Date: 12/14/2004
 

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


[PHP-DB] String question

2004-12-14 Thread Chris Payne
Hi there everyone,

 

I am having to read a string with text in, but the way the DB is written in
the same string you have the price, for example

 

CASARON 4G

50lb Sacks in Ton Lots

$88.00

 

How can I strip out the 88.00 (Baring in mind it could be any number)  into
its own string?

 

Thank you.

 

Chris


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.816 / Virus Database: 554 - Release Date: 12/14/2004