keyongtech


  keyongtech > php > 05/2008

 #1  
05-11-08, 12:07 PM
skezzolo
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
 #2  
05-12-08, 10:32 AM
Álvaro G. Vicario
skezzolo 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.
Similar Threads
How to query the index value of associative array

Hello PowerShellers, How do I return the index value of an associative array? I'm referencing "Pro Windows PowerShell" by Hristo Deshev, p. 18-24 Problem 1: Array and...

Data structure for fast associative array with lookup by both key and index

Hi all, I'm looking for a data structure for an associative array with the following properties: - Maintains key/value pairs. - Remembers the sequence order in which the...

finding the index name of an associative array

myarray=array() myarray['a']=1 myarray['b']=1 myarray['c']=1 Is there an iterative way to find out the array index values ('a', 'b' and 'c') of myarray?

Creative a regular array from associative array?

Re, I have the following array: $my_array[x]['date'] ['time'] ['filename'] how do I create a $time_array that will ONLY have all values of $my_array[x]['time']? i can...

unexpected result reading an associative array

Hi, I have a text file on a website. This file contains data like: 01,1;02,0;03,2;04,1 On a different webserver this file is read with php. I use the following: <?php


All times are GMT. The time now is 12:24 PM. | Privacy Policy