Welcome to Geeklog, Anonymous Saturday, December 21 2024 @ 09:46 pm EST

Geeklog Forums

Static Pages - return statement


Status: offline

gbarnes

Forum User
Newbie
Registered: 12/07/03
Posts: 4
I used PHP in a static page. I originally used the echo command - this produced the result I expected but outside the block as indicated by the documentation.

However, when I changed my echo commands to return commands I just get a mess.

Any thoughts?
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany

Status: offline

gbarnes

Forum User
Newbie
Registered: 12/07/03
Posts: 4
I am using return. I have read the page. I also followed the rules: -
You will need to enable the use of PHP for each individual page.
Don't include your PHP code in tags.
Don't use echo or print.
Use return to return the content you want to be displayed.

BUT when I use RETURN it does NOT work. Echo produces the best result(if out of the block as indicated in the documentation).

If I am missing something else then I would be grateful for it to be pointed out to me. I am using Return with no success while using echo with some resonably good results.
 Quote

Status: offline

exaurdon

Forum User
Regular Poster
Registered: 08/13/03
Posts: 107
This is really basic, but just to check, you are aware you can only use a single return statement in your php right? (Return in a php staticpage should print the given value, and then will end the php)

Exaurdon~
 Quote

Status: offline

gbarnes

Forum User
Newbie
Registered: 12/07/03
Posts: 4
It is very basic but I am also a newbie. I had noticed my first return statment worked but ignored it in blind faith.

As I said I needed it pointed out. I will no need to re-evaluate what I am trying to do - though echo works VERY well - if outside the block for my task.

THANKS
 Quote

Status: offline

exaurdon

Forum User
Regular Poster
Registered: 08/13/03
Posts: 107
Hello again,

Generally, what you do for php mode, is collect all of the text you want into a variable, and then return the variable at the end of the script.

Example: (Assuming you want to print 'hello world!')
Text Formatted Code
$echotext = "Hello";
$echotext .= " World";
$echotext .= "!";
return $echotext;
 


(Obviously, that could also be done in a single line, but I was just trying to show an example of how you can stack a variable and return it)

Exaurdon~
 Quote

Status: offline

gbarnes

Forum User
Newbie
Registered: 12/07/03
Posts: 4
Thanks. Used this method and it worked well. Now everything is neatly displayed in the block Smile

Thanks again.
 Quote

All times are EST. The time is now 09:46 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content