jamesxg1 Posted March 4, 2009 Share Posted March 4, 2009 <?php session_start(); if (!isset($_SESSION['logged'])) { header("Location: ../index.php"); exit(); } function smiley(&$text) { $text = ereg_replace("", "<img src='../template/images/smiley/cheesy.gif'>", $text); $text = ereg_replace(":@", "<img src='../template/images/smiley/angry.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/cool.gif'>", $text); $text = ereg_replace(":'\(", "<img src='../template/images/smiley/cry.gif'>", $text); $text = ereg_replace(":-\[", "<img src='../template/images/smiley/embarrassed.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/grin.gif'>", $text); $text = ereg_replace(":-X", "<img src='../template/images/smiley/lipsrsealed.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/rolleyes.gif'>", $text); $text = ereg_replace(":\(", "<img src='../template/images/smiley/sad.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/shocked.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/smiley.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/tongue.gif'>", $text); $text = ereg_replace(":\/", "<img src='../template/images/smiley/undecided.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/wink.gif'>", $text); } // this starts the function on the var smiley($var here); ?> how do i make this work on the whole page instead of doing this ? $line = ""; smiley($line); print "$line"; can anyone help ? Many thanks James. Link to comment https://forums.phpfreaks.com/topic/147991-solved-how-do-i-make-a-function-work-for-the-whole-page/ Share on other sites More sharing options...
jamesxg1 Posted March 4, 2009 Author Share Posted March 4, 2009 someone please help ?? Link to comment https://forums.phpfreaks.com/topic/147991-solved-how-do-i-make-a-function-work-for-the-whole-page/#findComment-776753 Share on other sites More sharing options...
wildteen88 Posted March 4, 2009 Share Posted March 4, 2009 Whats wrong with just calling the function? Link to comment https://forums.phpfreaks.com/topic/147991-solved-how-do-i-make-a-function-work-for-the-whole-page/#findComment-776757 Share on other sites More sharing options...
jamesxg1 Posted March 4, 2009 Author Share Posted March 4, 2009 Whats wrong with just calling the function? you mean put smiley($VAR); ?, because my code uses rows from mysql and iv put it all like so. . . <?php print $var ?> and everytime i call the function it dont work :S Link to comment https://forums.phpfreaks.com/topic/147991-solved-how-do-i-make-a-function-work-for-the-whole-page/#findComment-776760 Share on other sites More sharing options...
wildteen88 Posted March 4, 2009 Share Posted March 4, 2009 Change your function to function smiley($text) { $text = ereg_replace("", "<img src='../template/images/smiley/cheesy.gif'>", $text); $text = ereg_replace(":@", "<img src='../template/images/smiley/angry.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/cool.gif'>", $text); $text = ereg_replace(":'\(", "<img src='../template/images/smiley/cry.gif'>", $text); $text = ereg_replace(":-\[", "<img src='../template/images/smiley/embarrassed.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/grin.gif'>", $text); $text = ereg_replace(":-X", "<img src='../template/images/smiley/lipsrsealed.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/rolleyes.gif'>", $text); $text = ereg_replace(":\(", "<img src='../template/images/smiley/sad.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/shocked.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/smiley.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/tongue.gif'>", $text); $text = ereg_replace(":\/", "<img src='../template/images/smiley/undecided.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/wink.gif'>", $text); return $text; } To use the function $myVar = smiley($row['myField']); OR <?php echo smiley($myVar); ?> Link to comment https://forums.phpfreaks.com/topic/147991-solved-how-do-i-make-a-function-work-for-the-whole-page/#findComment-776766 Share on other sites More sharing options...
jamesxg1 Posted March 4, 2009 Author Share Posted March 4, 2009 Change your function to function smiley($text) { $text = ereg_replace("", "<img src='../template/images/smiley/cheesy.gif'>", $text); $text = ereg_replace(":@", "<img src='../template/images/smiley/angry.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/cool.gif'>", $text); $text = ereg_replace(":'\(", "<img src='../template/images/smiley/cry.gif'>", $text); $text = ereg_replace(":-\[", "<img src='../template/images/smiley/embarrassed.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/grin.gif'>", $text); $text = ereg_replace(":-X", "<img src='../template/images/smiley/lipsrsealed.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/rolleyes.gif'>", $text); $text = ereg_replace(":\(", "<img src='../template/images/smiley/sad.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/shocked.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/smiley.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/tongue.gif'>", $text); $text = ereg_replace(":\/", "<img src='../template/images/smiley/undecided.gif'>", $text); $text = ereg_replace("", "<img src='../template/images/smiley/wink.gif'>", $text); return $text; } To use the function $myVar = smiley($row['myField']); OR <?php echo smiley($myVar); ?> works thanks mate (*) Link to comment https://forums.phpfreaks.com/topic/147991-solved-how-do-i-make-a-function-work-for-the-whole-page/#findComment-776788 Share on other sites More sharing options...
jamesxg1 Posted March 4, 2009 Author Share Posted March 4, 2009 sorry just wondering can i get this working the var isnt working ($siteurl) <?php session_start(); require("db/db.php"); $sql = "SELECT * FROM `settings`"; $query = mysql_query($sql); while ($settings = mysql_fetch_assoc($query)) { $siteurl = $settings['siteurl']; } function smiley($text) { $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/cheesy.gif'>", $text); $text = ereg_replace(":@", "<img src='$siteurl/template/images/smiley/angry.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/cool.gif'>", $text); $text = ereg_replace(":'\(", "<img src='$siteurl/template/images/smiley/cry.gif'>", $text); $text = ereg_replace(":-\[", "<img src='$siteurl/template/images/smiley/embarrassed.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/grin.gif'>", $text); $text = ereg_replace(":-X", "<img src='$siteurl/template/images/smiley/lipsrsealed.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/rolleyes.gif'>", $text); $text = ereg_replace(":\(", "<img src='$siteurl/template/images/smiley/sad.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/shocked.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/smiley.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/tongue.gif'>", $text); $text = ereg_replace(":\/", "<img src='$siteurl/template/images/smiley/undecided.gif'>", $text); $text = ereg_replace("", "<img src='$siteurl/template/images/smiley/wink.gif'>", $text); return $text; } ?> Link to comment https://forums.phpfreaks.com/topic/147991-solved-how-do-i-make-a-function-work-for-the-whole-page/#findComment-776833 Share on other sites More sharing options...
wildteen88 Posted March 5, 2009 Share Posted March 5, 2009 $var or $row['myField'] can be anything you want. $siteurl = smiley($settings['siteurl']); Link to comment https://forums.phpfreaks.com/topic/147991-solved-how-do-i-make-a-function-work-for-the-whole-page/#findComment-777556 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.