Connecting Tech Pros Worldwide Help | Site Map

how remove char around numbers

  #1  
Old April 13th, 2007, 01:55 AM
joe
Guest
 
Posts: n/a
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.

  #2  
Old April 13th, 2007, 04:15 AM
Aerik
Guest
 
Posts: n/a

re: how remove char around numbers


On Apr 12, 5:47 pm, "joe" <jcha...@gmail.comwrote:
Quote:
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

  #3  
Old April 13th, 2007, 04:15 AM
iktorn
Guest
 
Posts: n/a

re: how remove char around numbers


Aerik napisał(a):
Quote:
On Apr 12, 5:47 pm, "joe" <jcha...@gmail.comwrote:
Quote:
>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
  #4  
Old April 16th, 2007, 09:25 PM
joe
Guest
 
Posts: n/a

re: how remove char around numbers


Thanks Iktorn

I ended up doing $where_clause_array = split(" ",$where_clause);
$where_clause = "";

foreach ($where_clause_array as $t) {
$where_clause = $where_clause . " " . preg_replace("/
^'([1-9]+)'$/","$1",$t);
}

I tried using echo preg_replace("/'([0-9]+)'/","$1",$txt)."\n"; but
It did not work. I got stuck with another preg_rplace trying to
replace ('123123','somethingelse for (123123,'somethingelse. If I
could make $sql = preg_replace("/'([0-9]+)'/","$1",$sql) work may be
that would take care of all instances of numbers surrounde by quotes.





On Apr 12, 11:12 pm, iktorn <s...@phpfreelancer.netwrote:
Quote:
Aerik napisał(a):
>
Quote:
On Apr 12, 5:47 pm, "joe" <jcha...@gmail.comwrote:
Quote:
hello I have a string that has values in quotes 'hello' 'here' '199'
'something else'
>
Quote:
Quote:
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.
>
Quote:
Hm... use a regular expression, I'm thinking preg_replace ought to do
the trick...
>
Quote:
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 Walchttp://phpfreelancer.net

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Truncating numbers at end of string Alex Leach answers 5 February 7th, 2007 10:05 PM
Function to remove an item from a linked list failing ~1 out of 10,000 times Kieran Simkin answers 7 November 14th, 2005 06:42 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 09:56 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 03:15 AM