Jump to content

cant add function to a variable string


saeed_violinist

Recommended Posts

Hi friends, my first post  here...hope you can guide me

I 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]
<?php
include "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

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.