This is a discussion on Regular Expression Result as Associative Array Index within the PHP Language forums, part of the PHP Programming Forums category; Hi Everyone. $layout=ereg_replace("\[\[([a-z:0-9]+)\]\]", $dillo['\\1'], $layout); I'm trying to use the result ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi Everyone.
$layout=ereg_replace("\[\[([a-z:0-9]+)\]\]", $dillo['\\1'], $layout); I'm trying to use the result of a Regular Expression Match as an Index for the Associative Array $Dillo[], so that the to-replace content can be controlled from the to-be-replaced content. Unfortunately the code above doesn't seem to work. Any ideas? Sorry about my poor english, i'm workin' on that. skezzolo |
|
|||
|
skezzolo@gmail.com escribió:
> $layout=ereg_replace("\[\[([a-z:0-9]+)\]\]", $dillo['\\1'], $layout); The ereg_* functions will not be available in the PHP 6 core so you'd better get used preg_* equivalents: http://bitfilm.net/2007/09/21/becomi...-6-compatible/ > I'm trying to use the result of a Regular Expression Match as an Index > for the Associative Array $Dillo[], so that the to-replace content can > be controlled from the to-be-replaced content. If you need a match then you must use preg_match() rather than preg_replace(). Try this code: <?php $Dillo = array( 'alvaro:99' => 'Hello, world', ); $layout = 'foo:bar[[alvaro:99]]'; if( preg_match('/\[\[([a-z:0-9]+)\]\]/', $layout, $matches) ){ $layout = $Dillo[$matches[1]]; } echo $layout; ?> Of course, you'd need some extra checks. -- -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain -- Mi sitio sobre programación web: http://bits.demogracia.com -- Mi web de humor al baño María: http://www.demogracia.com -- |
![]() |
| Thread Tools | |
| Display Modes | |
|
|