Posted by meltedown on 12/20/05 06:32
Unknown wrote:
> Hi,
>
> I wonder if anyone can help with a basic question I have with editing a
> string.
>
> 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. So for example I would like $strPRICE to
> equal £14.99 in the first instance and ignore the contents of the string
> on either side.
>
> Can anyone advise on the command and syntax I need to use?
>
> Many thanks.
>
$text="DVD Region: 2 - Title: Star Wars - Price: L14.99 - Brought:
10/10/05";
preg_match("|- Price:(.*) -|",$text,$matches);
$matches will be:
[Array
(
[0] => - Price: L14.99 -
[1] => L14.99
)
]
Navigation:
[Reply to this message]
|