View Single Post

  #2 (permalink)  
Old 05-12-2008
Álvaro G. Vicario
 
Posts: n/a
Default Re: Regular Expression Result as Associative Array Index

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
--
Reply With Quote