Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more - View Single Post - Looking for a specific pattern in a text variable
View Single Post
Old 02-23-2010, 11:00 PM   #5 (permalink)
webman2015
Junior Member
 
Join Date: Mar 2009
Location: Long Island, NY
Posts: 13
Default Re: Looking for a specific pattern in a text variable

Yes, this will help, Thank you.

One more thing is still open though. There are other numbers and patterns in the descriptive text (I just used a small excerpt) and I need to look for the keyword "weight" then use the script you gave me to pull out the actual value right after it.

So, if the keyword "weight" is found, then pull out the numerical value after it. Then I also need to look at the letters immediately following the weight value. I just discovered that it may be measured in "oz", "lbs" or even "grams".

So, here is another example text:

Set includes: ruler, pencils, stapler, staple remover, staple wires, eraser, ball pen, tape, pad, blade, pencil sharpener, scissors, paper clips, push pins, and rotating caddy. Weight 1.2 lbs. Plastic, wood, metal, and paper. 6" x 5 1/4" x 6" high

And sometimes they use "lbs", sometimes "oz", and sometimes "grams". So I need to look for the keyword "weight", pull out the value, then look for a pattern matching either "oz", "lbs", or "grams".

I can use strpos to find the last part, easy enough. if (strpos($text, "lbs"))

How can I look for the keyword "weight", then pull out the value?

Thank you, this is helping a lot so far.
webman2015 is offline   Reply With Quote
Sponsored Links