Jasper Bryant-Greene wrote:
David Pollack wrote:
Ok, so this is the actual code that I'm using.
?
$string = ( 334, -53.44) ( 111 , 222 );
$testStr = $string;
// $string = str_replace( , , $string);
preg_match_all(-?([\d]+)?(\.[\d]+)?,$string, $matches);
I need to catch all instances of a coordinate in a give string. So far I
have this, which only works if the coordinate is in a certain format.
$string = (334,-53.44),(111,222);
$expression = '([(][-]?[0-9]*[.0-9]*?,[-]?[0-9]*[.0-9]*?[)])';
preg_match_all($expression, $string, $matches);
Wow, that definitely works. I would sort of like to know how to tweak the
regex, but maybe this is the best way of doing it. Is [0-9]*[.0-9]*? the
best way of looking for a number with decimals?
On 9/26/05, Murray @ PlanetThoughtful [EMAIL PROTECTED] wrote:
I need to catch all instances of a
David Pollack wrote:
I need to catch all instances of a coordinate in a give string. So far I
have this, which only works if the coordinate is in a certain format.
$string = (334,-53.44),(111,222);
$expression = '([(][-]?[0-9]*[.0-9]*?,[-]?[0-9]*[.0-9]*?[)])';
here's a horrid little bit of
Wow, that definitely works. I would sort of like to know how to tweak the
regex, but maybe this is the best way of doing it. Is [0-9]*[.0-9]*? the
best way of looking for a number with decimals?
Hi David,
Just to answer this question, I would probably use something like the
following pattern
keep it on the list please.
and you still didn't answer the question :-)
snip
preg_match_all($expression, $string, $matches);
^-- why ? ...
are you wrapping the variable in double quotes?
/snip
...and also from your code:
$string =
Ok, so this is the actual code that I'm using.
?
$string = ( 334, -53.44) ( 111 , 222 );
$testStr = $string;
// $string = str_replace( , , $string);
preg_match_all(-?([\d]+)?(\.[\d]+)?,$string, $matches);
var_dump($matches);
?
and the output is this...
*Warning*: No ending delimiter '-'
David Pollack wrote:
Ok, so this is the actual code that I'm using.
?
$string = ( 334, -53.44) ( 111 , 222 );
$testStr = $string;
// $string = str_replace( , , $string);
preg_match_all(-?([\d]+)?(\.[\d]+)?,$string, $matches);
preg_match_all(/-?([\d]+)?(\.[\d]+)?/, $string, $matches);
--
8 matches
Mail list logo