Solved

need to extract price range from a text

Posted on 2010-11-21
3
441 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
e commerce steps shown instead of self testing 2 58
Secure registration PHP 7 43
Conditional Array Element 7 28
Where does this error come from? 8 30
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

752 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