Har fundet min funtion:
function findfunctions($output) {
$var_start = "[";
$var_end = "]";
$content = ""; //Must be empty!
//if the number of variables is larger than 0
if(0 < (substr_count($output,$var_start)+substr_count($output,$var_end))) {
//Checkin if there is as much of $var_start as of $var_end in $output
if(substr_count($output,$var_start) == substr_count($output,$var_end)) {
//Running through $output, searching for variables
for($i = strpos($output,$var_start);$i<=strrpos($output,$var_end);$i++) {
//If $var_start is found, $count = the strpos of $var_start
if($output[$i] === $var_start) {
$count = $i;
}
//Putting all text between $var_start and $var_end in $var
if(strpos($output,$var_start,$count) < $i && $i < strpos($output,$var_end,$count)) {
$var .= $output[$i];
}
//When a $var_end is found, adding a | to $var to make room for a new variable
if($output[$i] === $var_end) {
$var .= "|";
}
}
//Explode $var to put all variables to an array.
$vars = explode("|",$var);
foreach($vars as $i) {
//Echoing the contents:
$content .= $i;
}
}
}
//Returning $output
return $content;
}
Måske ikke den mest optimale kode, men den virker til det formål at finde indholdet mellem to strenge.
Jeg har lavet den til at oversætte tekst, og finde funktions referencer i et cms.
Indlæg senest redigeret d. 12.11.2006 00:17 af Bruger #4442