nathanmaxsonadil Posted August 19, 2007 Share Posted August 19, 2007 I was wondering if this is the right way to put a function in a echo ? echo "<li><a href='{$_SERVER['PHP_SELF']}?example={myfunction($myvar['test'])}&... Quote Link to comment https://forums.phpfreaks.com/topic/65726-solved-is-this-the-right-way-to-put-a-function-in-a-echo/ Share on other sites More sharing options...
plutomed Posted August 19, 2007 Share Posted August 19, 2007 When I do them I do it like this : echo "<li><a href=\"".$_SERVER['PHP_SELF']."?example=".myfunction($myvar['test'])."&... So I dunno that way Quote Link to comment https://forums.phpfreaks.com/topic/65726-solved-is-this-the-right-way-to-put-a-function-in-a-echo/#findComment-328316 Share on other sites More sharing options...
trekerboy Posted August 19, 2007 Share Posted August 19, 2007 yeah, I also use the .myFunc($stuff). concatenation method Quote Link to comment https://forums.phpfreaks.com/topic/65726-solved-is-this-the-right-way-to-put-a-function-in-a-echo/#findComment-328328 Share on other sites More sharing options...
trq Posted August 19, 2007 Share Posted August 19, 2007 Did you even try your example? It will not work. Quote Link to comment https://forums.phpfreaks.com/topic/65726-solved-is-this-the-right-way-to-put-a-function-in-a-echo/#findComment-328332 Share on other sites More sharing options...
nathanmaxsonadil Posted August 20, 2007 Author Share Posted August 20, 2007 my example gives me error's Quote Link to comment https://forums.phpfreaks.com/topic/65726-solved-is-this-the-right-way-to-put-a-function-in-a-echo/#findComment-329171 Share on other sites More sharing options...
jcanker Posted August 20, 2007 Share Posted August 20, 2007 you are getting error b/c of the single quotes that are around the name of the href= and around the _SERVER element. Single quotes are not like parentheses; they don't nest inside of each other (generally....you might be able to create a bizzarre situation where they would, but let's not get into that now ) When I'm writing code, if I have a variable that refers to an array element, then I concatenate it using . so: echo "<li><a href=' . $_SERVER['PHP_SELF'] . " ?example= " .myfunction($myvar['test']) . " &somethingelse=goeshere' "; I put in some extra spaces to make it more obvious. another thing I will do is build a $page_content that all the html code gets added to as it builds, then echo $page_content when it's all finished. Quote Link to comment https://forums.phpfreaks.com/topic/65726-solved-is-this-the-right-way-to-put-a-function-in-a-echo/#findComment-329214 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.