Posted by jamen on 12/18/05 02:32
Unknown wrote:
> I am importing some code from a text file and it has lines like the
> following...
>
> DVD Region: 2 - Title: Star Wars - Price: £14.99 - Brought: 10/10/05
> DVD Region: 1 - Title: Empire Strikes - Price: $9.50 - Brought: 05/05/02
>
> All I am purely interested in is pulling the price out of the string
> that each line is held in.
Look into regular expressions
$str = "DVD Region: 2 - Title: Star Wars - Price: £14.99 - Brought:
10/10/05";
if(preg_match("#Price: (\\S+)#", $str, $m)){
echo "price: " . $m[1];
}
preg_match_all can find all matches in a string
[Back to original message]
|