PHP Replace chars by functions

Posted by user1860570 on Stack Overflow See other posts from Stack Overflow or by user1860570
Published on 2012-11-28T16:41:27Z Indexed on 2012/11/28 17:04 UTC
Read the original article Hit count: 266

Filed under:
|
|
|

I try change characters by functions

 <?php
$string = "Hi everybody people [gal~images/articles~100~100~4]  here other imagen [gal~images/products~100~100~3]";

$regex = "/\[(.*?)\]/";
preg_match_all($regex, $string, $matches);

for($i=0; $i<count($matches[1]);$i++)
{
$match = $matches[1][$i];
$array = explode('~', $match);

//$newValuet="gal("".$array[1]."","".$array[2]."","".$array[3]."","".$array[4]."")";

$newValue="gal(".$array[1].",".$array[2].",".$array[3].",".$array[4].")";


$string = str_replace($matches[0][$i],$newValue,$string);

}

echo $string;
?>

The problem here :

$newValue="gal(".$array[1].",".$array[2].",".$array[3].",".$array[4].")";


    $string = str_replace($matches[0][$i],$newValue,$string);

Function no give the right results i try differents methods but continue the problems , please i see all functions but no get this works if you can answer please put me some modification of this code for i can understand , thank´s a lot for all help

© Stack Overflow or respective owner

Related posts about php

Related posts about function