Hi,
I want to manuplate every string between [test] and [/test] by explode it and return new string.
For example I have the following string:
$string="many lines
[test]word1|word2|word3[/test]
";
Then I want to replace :
[test]word1|word2|word3[/test]
By:
1: word1
2: word2
3: word3
I use:
$string=eregi_replace("[test]([\[]*)[/test]",words('\1'),$string);
where «words» is a function:
function words($mywords){
$line=explode("|",$mywords);
$lines="1: $line[0] <BR> 2: $line[1] <BR> 3: $line[2] <BR>";
return $lines;
}
What is wronge in my code ??
The code is:
<?
$string="many lines ....<BR>
[test]word1|word2|word3[/test]
<BR>
many lines ....<BR>
<BR>
[test]word1|word2|word3[/test]
<BR>
many lines ....
";
$string=eregi_replace("[test]([\[]*)[/test]",words('\1'),$string);
function words($mywords){
$line=explode("|",$mywords);
$lines="1: $line[0] <BR> 2: $line[1] <BR> 3: $line[2] <BR>";
return $lines;
}
echo $string;
?>
The output shoud be like:
many lines ....
1: word1
2: word2
3: word3
many lines ....
1: word1
2: word2
3: word3
many lines ....
==================
Thanks