Page 1 of 1

array search

Posted: Fri Apr 20, 2007 1:44 pm
by yshaf13
hi, can someone please help me out with an array search function that would find any number surrounded with a "^" before and after?

Posted: Fri Apr 20, 2007 1:59 pm
by John Cartwright
I usually don't do this, so consider yourself lucky :) How I would do it

Code: Select all

$stack = array('test string ^3423432^', '^432423^ test string', 'dfdsffdsfd ^342342^');

$found = array_map(create_function('$stack', 'preg_match("#\^([0-9]+)\^#", $stack, $matches); return $matches[1];'), $stack);
A more simple version would be to use a foreach(), and preg_match using the above pattern and place $matches[1] into a new array of numbers.

//outputs: Array ( [0] => 3423432 [1] => 432423 [2] => 342342 )

re

Posted: Fri Apr 20, 2007 2:27 pm
by yshaf13
thank alot, i really do feel lucky!