need to extract price range from a text

Posted on 2010-11-21
Last Modified: 2012-05-10
i need to extrac the price range like $XX-$XXX USD, from text. the X may be single digit or many digits to follow. any help with this.
Question by:rajccs
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 13

Accepted Solution

dsmile earned 500 total points
ID: 34182625
Try this
$pattern = '/(\$[0-9]+-\$[0-9]+ USD)/';
echo $string = <<< TXT
dummy text dummy text dummy text $112-$1324 USD dummy text dummy text 
dummy text dummy text $1312-$13624 USD dummy text dummy text dummy text $14412-$13244 USD dummy text dummy text 
dummy text $1012-$13244 USD dummy text dummy text dummy text $112-$13242 USD dummy text dummy text 
preg_match_all($pattern, $string, $result);

Open in new window

LVL 10

Expert Comment

ID: 34182723
Try dsmile code, but with:

$pattern = '/(\$[0-9]+)-(\$[0-9]+)/';

this will split every $XX-$XXX into lower and upper boundary
LVL 35

Expert Comment

by:Terry Woods
ID: 34193694

$pattern = '/(\$[0-9.]+)-(\$[0-9.]+)/';

if you want to allow cents...

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question