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)


50lb Sacks in Ton Lots


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

NB: note the difference between using single and double quotes when
defining your regexp. e.g:

$regexp = '/^.*\$[ \t]?([0-9]+\.[0-9]{2})$/s';


$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:


$myString = "
50lb Sacks in Ton Lots

$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");


Thank you.


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

-- PHP Database Mailing List ( To unsubscribe, visit:

Reply via email to