I try replace characters from string and put others , for this use preg_replace_callback function , the problem is this function change order of original text and show differents results
For example if the string it´s :
Hello everybody [1-2-3] this it´s one test [4-5-6-7-8] --- > ORIGINAL TEXT
The script search the [ ] and separate this content with [ ] from the other text , but show me as i put here :
1-2-3 4-5-6-7-8 Hello Everybody this it´s one test --- > BAD RESULT
When the right order it´s the first without [ ]
Hello everybody 1-2-3 this it´s one test 4-5-6-7-8
The script i create :
<?php
$text = " This is a test [gal~ruta~100~100] This is other test [gal~ruta2~100~100]";
function gal($matches)
{
global $text;
$exp=explode("~",$matches[1]);
$end=str_replace($matches[1],$a,$text);
if ($exp[0]=="gal")
{
$a="".$exp[1]."".$exp[2]."".$exp[3]."";
echo $a;
}
}
echo preg_replace_callback(
"/\[(.*?)\]/",
"gal",
$text);
?>
Thank´s everybody for the help