UBB-script error
daanv - 26/06/2006 18:53
Nieuw lid
Hallo,
Wie weet waarom hij de fout geeft 'undefined variable $tekst' als ik $tekst in de database wil zetten?
function smily($tekst)
{
$smily = array (
":)",
":(",
";)",
":O",
":P",
";cool",
":@:",
":S",
":C",
":$",
":duivel",
":?",
":!",
":lol",
":twist",
":rol",
":mad",
":eyes",
":>",
);
$img = array (
"<img src=\"images/smileys/icon_biggrin.gif\">",
"<img src=\"images/smileys/icon_frown.gif\">",
"<img src=\"images/smileys/icon_wink.gif\">",
"<img src=\"images/smileys/icon_surprised.gif\">",
"<img src=\"images/smileys/icon_razz.gif\">",
"<img src=\"images/smileys/icon_cool.gif\">",
"<img src=\"images/smileys/icon_twisted.gif\">",
"<img src=\"images/smileys/icon_neutral.gif\">",
"<img src=\"images/smileys/icon_confused.gif\">",
"<img src=\"images/smileys/icon_redface.gif\">",
"<img src=\"images/smileys/icon_evil.gif\">",
"<img src=\"images/smileys/icon_question.gif\">",
"<img src=\"images/smileys/icon_idea.gif\">",
"<img src=\"images/smileys/icon_lol.gif\">",
"<img src=\"images/smileys/icon_twisted.gif\">",
"<img src=\"images/smileys/icon_rolleyes.gif\">",
"<img src=\"images/smileys/icon_mad.gif\">",
"<img src=\"images/smileys/icon_eek.gif\">",
"<img src=\"images/smileys/icon_arrow.gif\">",
);
$aantal = count($smily);
for ($var = 0; $var < $aantal; $var++ )
{
$tekst = str_replace($smily[$var],$img[$var],$bericht);
}
return $tekst;
mysql_query("INSERT INTO forum_topics (inhoud) VALUES ('".$tekst."''')") or die (mysql_error());
}
function smily( $tekst )
{
":)" ,
":(" ,
";)" ,
":O" ,
":P" ,
";cool" ,
":@:" ,
":S" ,
":C" ,
":$" ,
":duivel" ,
":?" ,
":!" ,
":lol" ,
":twist" ,
":rol" ,
":mad" ,
":eyes" ,
":>" ,
) ;
"<img src=\" images/smileys/icon_biggrin.gif\" >" ,
"<img src=\" images/smileys/icon_frown.gif\" >" ,
"<img src=\" images/smileys/icon_wink.gif\" >" ,
"<img src=\" images/smileys/icon_surprised.gif\" >" ,
"<img src=\" images/smileys/icon_razz.gif\" >" ,
"<img src=\" images/smileys/icon_cool.gif\" >" ,
"<img src=\" images/smileys/icon_twisted.gif\" >" ,
"<img src=\" images/smileys/icon_neutral.gif\" >" ,
"<img src=\" images/smileys/icon_confused.gif\" >" ,
"<img src=\" images/smileys/icon_redface.gif\" >" ,
"<img src=\" images/smileys/icon_evil.gif\" >" ,
"<img src=\" images/smileys/icon_question.gif\" >" ,
"<img src=\" images/smileys/icon_idea.gif\" >" ,
"<img src=\" images/smileys/icon_lol.gif\" >" ,
"<img src=\" images/smileys/icon_twisted.gif\" >" ,
"<img src=\" images/smileys/icon_rolleyes.gif\" >" ,
"<img src=\" images/smileys/icon_mad.gif\" >" ,
"<img src=\" images/smileys/icon_eek.gif\" >" ,
"<img src=\" images/smileys/icon_arrow.gif\" >" ,
) ;
for ( $var = 0 ; $var < $aantal ; $var ++ )
{
$tekst = str_replace ( $smily [ $var ] , $img [ $var ] , $bericht ) ;
}
return $tekst ;
}
11 antwoorden
Gesponsorde links
daanv - 26/06/2006 19:09
Nieuw lid
Klopt, heb ik nu weg gehaald maar hij blijft dezelfde error geven.
ikkedikke - 26/06/2006 19:16
PHP expert
het zal niet helpen, maar na de return wordt de functie afgebroken. waarom staat die query er dan nog achter?
daanv - 26/06/2006 19:19
Nieuw lid
Helpt niet, toch bedankt. Ziet iemand het wel?
Rifke - 26/06/2006 20:34 (laatste wijziging 26/06/2006 20:38)
Nieuw lid
Deze heb ik in gebruik misschien heb jij er ook wat aan. In mijn opzicht is deze eenvoudiger.
<?php
function smily($tekst) {
$emo_path = "../ICONS/"; // Plaats / achter de dir
$smile = array(
':D' => '<img src="'.$emo_path.'icon_biggrin.gif" border="0" alt="Big Grin" >',
':s' => '<img src="'.$emo_path.'icon_confused.gif" border="0" alt="confused" >'
/* enzovoort */
);
$tekst = str_replace(array_keys($smile),array_values($smile), $tekst);
return $tekst;
}
?>
<?php
function smily( $tekst ) {
$emo_path = "../ICONS/" ; // Plaats / achter de dir
':D' => '<img src="' . $emo_path . 'icon_biggrin.gif" border="0" alt="Big Grin" >' ,
':s' => '<img src="' . $emo_path . 'icon_confused.gif" border="0" alt="confused" >'
/* enzovoort */
) ;
return $tekst ;
}
?>
daanv - 01/07/2006 13:00 (laatste wijziging 01/07/2006 13:00)
Nieuw lid
Veranderd naar het ubb-script van rifke, iemand idee wat er toch fout is aan deze code?
$tekst = $_POST['bericht']
function smily($tekst) {
$smile = array(
':)' => '<img src=\"images/smileys/icon_biggrin.gif\">',
':(' => '<img src=\"images/smileys/icon_frown.gif\">'
';)' => '<img src=\"images/smileys/icon_wink.gif\">',
':O' => '<img src=\"images/smileys/icon_surprised.gif\">'
':P' => '<img src=\"images/smileys/icon_razz.gif\">',
':cool' => '<img src=\"images/smileys/icon_cool.gif\">'
':@' => '<img src=\"images/smileys/icon_twisted.gif\">',
':s' => '<img src=\"images/smileys/icon_neutral.gif\">'
':c' => '<img src=\"images/smileys/icon_confused.gif\">',
':$' => '<img src=\"images/smileys/icon_redface.gif\">'
':duivel' => '<img src=\"images/smileys/icon_evil.gif\">',
':?' => '<img src=\"images/smileys/icon_question.gif\">'
':!' => '<img src=\"images/smileys/icon_idea.gif\">',
':lol' => '<img src=\"images/smileys/icon_lol.gif\">'
':twist' => '<img src=\"images/smileys/icon_twisted.gif\">',
':rol' => '<img src=\"images/smileys/icon_rolleyes.gif\">'
':mad' => '<img src=\"images/smileys/icon_mad.gif\">',
':eyes' => '<img src=\"images/smileys/icon_eek.gif\">'
':>' => '<img src=\"images/smileys/icon_arrow.gif\">',
);
$tekst = str_replace(array_keys($smile),array_values($smile), $tekst);
return $tekst;
}
}
mysql_query("INSERT INTO forum_topics (id, gebruikersnaam, titel, inhoud, categorie, replyto) VALUES ('', '".$gebruikersnaam."', '".$onderwerp."', '".$tekst."', '".$categorie."', '')") or die (mysql_error());
$tekst = $_POST [ 'bericht' ]
function smily( $tekst ) {
':)' => '<img src=\"images/smileys/icon_biggrin.gif\">' ,
':(' => '<img src=\"images/smileys/icon_frown.gif\">'
';)' => '<img src=\"images/smileys/icon_wink.gif\">' ,
':O' => '<img src=\"images/smileys/icon_surprised.gif\">'
':P' => '<img src=\"images/smileys/icon_razz.gif\">' ,
':cool' => '<img src=\"images/smileys/icon_cool.gif\">'
':@' => '<img src=\"images/smileys/icon_twisted.gif\">' ,
':s' => '<img src=\"images/smileys/icon_neutral.gif\">'
':c' => '<img src=\"images/smileys/icon_confused.gif\">' ,
':$' => '<img src=\"images/smileys/icon_redface.gif\">'
':duivel' => '<img src=\"images/smileys/icon_evil.gif\">' ,
':?' => '<img src=\"images/smileys/icon_question.gif\">'
':!' => '<img src=\"images/smileys/icon_idea.gif\">' ,
':lol' => '<img src=\"images/smileys/icon_lol.gif\">'
':twist' => '<img src=\"images/smileys/icon_twisted.gif\">' ,
':rol' => '<img src=\"images/smileys/icon_rolleyes.gif\">'
':mad' => '<img src=\"images/smileys/icon_mad.gif\">' ,
':eyes' => '<img src=\"images/smileys/icon_eek.gif\">'
':>' => '<img src=\"images/smileys/icon_arrow.gif\">' ,
) ;
return $tekst ;
}
}
mysql_query ( "INSERT INTO forum_topics (id, gebruikersnaam, titel, inhoud, categorie, replyto) VALUES ('', '" . $gebruikersnaam . "', '" . $onderwerp . "', '" . $tekst . "', '" . $categorie . "', '')" ) or
die ( mysql_error ( ) ) ;
Hij geeft een fout in function smily($tekst){
nielsvdwal - 01/07/2006 13:05
PHP gevorderde
en wat is de fout?
Gerard - 01/07/2006 13:06
Ouwe rakker
$tekst = $_POST['bericht']
je mist een ;
waarom wil je uberhaupt HTML in je database zetten (de hele smilies). Gooi die smilie functie er maar overheen als je alles weergeeft. Als nu iemand het zaakje wil editen krijg hij die hele <img src=""> te zien.
letscode - 01/07/2006 14:17 (laatste wijziging 01/07/2006 14:17)
HTML beginner
dus:
':eyes' => '<img src=\"images/smileys/icon_eek.gif\">',
':>' => '<img src=\"images/smileys/icon_arrow.gif\">'
);
':eyes' => '<img src=\"images/smileys/icon_eek.gif\">' ,
':>' => '<img src=\"images/smileys/icon_arrow.gif\">'
) ;
!!
Gesponsorde links
Dit onderwerp is gesloten .