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
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.