Laufen Funktionen parallel in PHP?

ZodiacXP

Erfahrenes Mitglied
Mein PHP: rennt los, stolpert, fällt auf den Kopf, vergisst was aber rennt mutig weiter.
Wie ein kleines Kind.

PHP:
/**
	 * Take array-keys as template-variable and replace it with it's content
	 *
	 * @param string $sContent The content with template-vars in it
	 * @param string $aReplace Variables that shall be replaced
	 * @return string
	 * @copyright all rigths reserved
	 */
	function ReplaceTemplateVars($sContent, $aReplace) {
		// replace the template-vars - 1.0.0
		do {
			$sNeedle = TPL_OPEN . key($aReplace) . TPL_CLOSE;	// the template-var - 1.0.0
			$sContent = str_replace($sNeedle, current($aReplace), $sContent);
		} while (next($aReplace));
		return $sContent;
	}

In $aReplace packe ich zur Zeit 3 Template-Variablen wovon nur eine im Content ersetzt wird. Schreibt man aber in die Schleife so etwas sinnloses wie "echo ' ';" (nur ein Leerzeichen) direkt am Anfang ersetzt er alle.
 
Probier’s mal mit einem foreach-Konstrukt:
PHP:
foreach ($aReplace as $key => $val) {
	$sNeedle = TPL_OPEN . $key . TPL_CLOSE;    // the template-var - 1.0.0
	$sContent = str_replace($sNeedle, $val, $sContent);
}
 
Ui. Hätt ich dazu schreiben sollen.

Möcht kein foreach benutzen, weil das glatt 40x solang brauchen würde, kein
while(list($key, $val) = each($aReplace) weil das doppelt so lang braucht und keine for schleife mit array_keys in gesonderter Variablen, weil das mehr Speicher braucht.

Es geht nicht in meinen Kopf rein was PHP da falsch machen kann oder wo mein Denkfehler ist.
 
Zurück