Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

need to extract price range from a text

Posted on 2010-11-21
3
Medium Priority
?
445 Views
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.
0
Comment
Question by:rajccs
[X]
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
3 Comments
 
LVL 13

Accepted Solution

by:
dsmile earned 2000 total points
ID: 34182625
Try this
<pre>
<?php
$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 
TXT;
preg_match_all($pattern, $string, $result);
print_r($result);
?>

Open in new window

0
 
LVL 10

Expert Comment

by:jfromanski
ID: 34182723
Try dsmile code, but with:

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

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

Expert Comment

by:Terry Woods
ID: 34193694
And:

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

if you want to allow cents...
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

664 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