Function includen zum Smiley Load

DeMoehn

Mitglied
Hi Leute.
Ich hab immernoch ein File "readNews".
In diesem File steht zunächst ma:
PHP:
$text=$reihe->text;
$text =setSmile($text);
...
in der includeten Datei steht
PHP:
<?php
function setSmile($text) {
$smile = array(";-)","8-(",":)",":-P",";-P",";=)");
$smileEr = array('<img src="images/cool.gif" width="15" height="15">','<img src="images/redface.gif" width="15" height="15">','<img src="images/smile.gif" width="15" height="15">','<img src="images/tongue.gif" width="15" height="15">','<img src="images/upto.gif" width="15" height="15">','<img src="images/wink.gif" width="15" height="15">');
for ($i = 0; $i < count($smile); $i++) {
$text = str_replace($smile[$i], "hi", $text);
echo "hi";
}
}
?>
das echo "hi "wird geschrieben, 5 mal oder so, zumindest gehts.
Aber die Smileys werden nicht durch "hi" ersetzt.
PS: Hi war nur zum testen da, weil das andere nicht klappte, aber hi ja auch nich :)
 
PHP:
<?php
function setSmile($text) {
$smile = array(";-)","8-(",":)",":-P",";-P",";=)");
$smileEr = array('<img src="images/cool.gif" width="15" height="15">','<img src="images/redface.gif" width="15" height="15">','<img src="images/smile.gif" width="15" height="15">','<img src="images/tongue.gif" width="15" height="15">','<img src="images/upto.gif" width="15" height="15">','<img src="images/wink.gif" width="15" height="15">');
for ($i = 0; $i < count($smile); $i++) {
$Mytext = str_replace(":-)", "hi", $text);
return($Mytext);
}
}
function head($head) {
echo "<td bgcolor='#993300'><span class='uberschrift'>$head</span></td>";
}
?>
geht irgendwie auch nich, *heul* was mach cih nur falsch
 
Seit PHP 4.0.5 kann jeder Parameter von [PHPF]str_replace[/PHPF] auch ein Array sein.

Wenn du also PHP 4.0.5 oder höher verwendest, dann kannst du es folgenderweise machen:
PHP:
function setSmile($text) {
$smile = array(";-)","8-(",":)",":-P",";-P",";=)");
$smileEr = array('<img src="images/cool.gif" width="15" height="15">','<img src="images/redface.gif" width="15" height="15">','<img src="images/smile.gif" width="15" height="15">','<img src="images/tongue.gif" width="15" height="15">','<img src="images/upto.gif" width="15" height="15">','<img src="images/wink.gif" width="15" height="15">');
$newtext = str_replace($smile, $smileEr, $text);
return $newtext;

Gruß
Marvin
 
aber wenn ich das ganze so schreibe
PHP:
function urlThis($testText) {
$testText = preg_replace("/(http:\/\/(.*))[\s]*/", "<a href=\\1>\\1</a> ", $testText);
return($testText);
}
und dann in readNews.php include und dort wieder
PHP:
urlThis($myText2);
schreibe, dann passiert nichts, genau wie mit der smiley funktion.
Die geht ja auch nicht als funktion, nur direkt, hat jemand eine ahnung?
 
Zurück