|
Posted by iktorn on 04/13/07 03:12
Aerik napisał(a):
> On Apr 12, 5:47 pm, "joe" <jcha...@gmail.com> wrote:
>> hello I have a string that has values in quotes 'hello' 'here' '199'
>> 'something else'
>>
>> I need to remove the quotes only when they are around numbers.
>> To make the string lookg like 'hello' 'here' 199 'something else'
>> any ideas on how to do this? thanks.
>
> Hm... use a regular expression, I'm thinking preg_replace ought to do
> the trick...
>
> Aerik
>
<?php
$txt = array("'sdfsdfsd'","'as34444'","'234sdfd'","'2344'");
foreach ($txt as $t) {
echo preg_replace("/^'([0-9]+)'$/","$1",$t)."\n";
}
$txt = "'sdfsdfsd' 'as34444' '12' '234sdfd' '2344'";
echo preg_replace("/'([0-9]+)'/","$1",$txt)."\n";
--
Wiktor Walc
http://phpfreelancer.net
[Back to original message]
|