saeed_violinist Posted November 21, 2006 Share Posted November 21, 2006 Hi friends, my first post here...hope you can guide meI have defined a function to greet the visitors based on the day and the time of a day, the function works fine itself, but when I try to call it in a string in middle of a html table, the function runs before anything in the string. the code for calling function is :[code]<?phpinclude "data/inc.php";$GreetContent = "<table border=\"1 px\"><tr><td>hello saeed, " . GreetDay() . " </td></tr></table>\n";echo $GreetContent?>[/code] If we assume that the GreetDay() outpot is something like "welcome, today is Mondey" , when I run the script the html outpot will be :[code]welcome, today is Monday<table border="1 px"><tr><td>hello saeed, </td></tr></table>[/code]I want to know why "GreetDay()" function runs prior to "Hello saeed" and not placed in the table I defined ?thanks! Link to comment https://forums.phpfreaks.com/topic/27916-cant-add-function-to-a-variable-string/ Share on other sites More sharing options...
hitman6003 Posted November 21, 2006 Share Posted November 21, 2006 is your function, GreetDay, returning the value "welcome, today is Monday", or is it echoing out that value? The way that you are using it, you need to have it return a value.[code]function GreetDay() { return "Welcome, today is " . date('l');}[/code]not:[code]function GreetDay() { echo "Welcome, today is " . date('l');}[/code] Link to comment https://forums.phpfreaks.com/topic/27916-cant-add-function-to-a-variable-string/#findComment-127704 Share on other sites More sharing options...
saeed_violinist Posted November 21, 2006 Author Share Posted November 21, 2006 Thanks a lot! I used "echo" but now with return I get the desired result. Link to comment https://forums.phpfreaks.com/topic/27916-cant-add-function-to-a-variable-string/#findComment-127839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.