Calling A Function From Within Heredoc Syntax

liunx

Guest
How do I call a function from within the heredoc syntax in PHP? I would like to use a function to display parts of the entire text within the heredoc syntax repeatedly throughout itself.<br /><br />For example, the text that I would like to display is:<br />Mary had a little lamb, little lamb, little lamb.<br /><br />The entire sentence is contained within the heredoc syntax and I would like to use a function to repeat little lamb three times instead of having to type it in full within the syntax. Can this be done? I'm tearing my hair out on this.<br /><br />Edit: I could probably use a variable to store little lamb but unfortunately the piece of text that I wish to repeat has slight variations that makes a function more suitable instead. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /><!--content-->
I'm pretty sure the heredoc syntax does not allow you to use functions within it, only variables <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /><!--content-->
Ahhh.. Is there a way of storing the heredoc text in a variable in one particular function in a file and call it up again within another heredoc text in another function on another file?<!--content-->
Can you explain in more detail what you are trying to do.<br />And maybe give examples of what yo have tried.<br /><br />Don't forget when using heredoc<br />the delimiter must be by itself on a line after the text<br />The only exception is a ;<!--content-->
I would like to have two files using the heredoc syntax, one handling the user interface and the other handling the headers and footers of a page.<br /><br />The one handling the UI is a function accepting parameters to set the attributes of the UI for example, a button would have the title and href link attributes which would be set via a function.<br /><br />The function handling the headers and footers has buttons inside them and I would like to somehow get the output of the earlier-mentioned function at various places within the heredoc text output of this function.<br /><br />I have tried using a return instead of an echo for the UI function in one file. Then I called the UI function from the other file containing the header/footer function. I plugged the output of the UI function to a variable and I inserted the variable into the header/footer heredoc text.<br /><br />The error I get is a parse error stating something about an unexpected $ sign.<br /><br />I've checked my brackets and they all match. I've checked my variable names and they all have their corresponding $ signs. I've also checked that when the UI function accepts a parameter, it has '' delimiting the parameters.<br /><br />Would be grateful to see a working implementation of this idea.<!--content-->
Well, if the variable is a global variable (if it is visible in the scope of the function where you want to use it), then yes, I think you can.<!--content-->
What is the difference between superglobal and global variables? I think I understand how they work when it comes to passing data between a form and another output page but I don't know how to implement a superglobal in this case. The reason why I'm asking is because I read up somewhere on the PHP manual which says that globals would soon be deprecated?<br /><br />In this case, which superglobal array should I use? Environment, session, server, request, post, get, cookies or?<!--content-->
Forgive me for butting in, but for my own knowledge, what is "heredoc syntax"?<br /><br />Thx....resume thread. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /><!--content-->
<!--QuoteBegin-stevevan+Oct 19 2004, 07:59 PM--><div class='quotetop'>QUOTE(stevevan @ Oct 19 2004, 07:59 PM)</div><div class='quotemain'><!--QuoteEBegin-->Forgive me for butting in, but for my own knowledge, what is "heredoc syntax"?<br /><br />Thx....resume thread. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /><!--QuoteEnd--></div><!--QuoteEEnd--><br /> <!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->Here-doc syntax is just an easy convention for specifying strings that take up several lines and/or that could have otherwise reserved characters<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Here is more information;<br /><br /><a href="http://kwiki.org/?HereDoc" target="_blank">http://kwiki.org/?HereDoc</a><!--content-->
The superglobals are environment variables that are readily available anywhere in a script. A global variable is a variable you declare as being accessible in the scope of where you declare it to be accessible.<br /><br />What you have seen about global variables being deprecated is something that has already happened. Quite some time ago, actually <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /> It's basically a security measure: by default, PHP used to have the register_globals configuration directive set to 1 and they changed it to 0. Read more about it <a href="http://www.schlossnagle.org/~george/blog/archives/271_Why_register_globals_and_remote_includes_are_a_serious_problem_in_PHP.html" target="_blank"> here</a> and <a href="http://www.php.net/manual/en/language.variables.scope.php" target="_blank">here</a>.<!--content-->
 
Back
Top