0

How can I call a function like below:

 $display_table="<table><tr><td>FUNCTION_CALL_HERE();</td></tr></table>";

I have tried brackets and all, but the function wont get called...

How should I make this work? (syntax problems I think)

Thanks

asked Nov 19, 2009 at 4:20
0

3 Answers 3

2

is there a reason you cannot use string concatenation? Assuming the output of FUNCTION_CALL_HERE is a string.

$display_table="<table><tr><td>" . FUNCTION_CALL_HERE() . "</td></tr></table>";
answered Nov 19, 2009 at 4:22
Sign up to request clarification or add additional context in comments.

Comments

0
 $display_table="<table><tr><td>" . FUNCTION_CALL_HERE() . "</td></tr></table>";
answered Nov 19, 2009 at 4:22

Comments

0

Alternatively:

$display_table="<table><tr><td>{FUNCTION_CALL_HERE()}</td></tr></table>";

Actually should be:

<?php
function asdf() {
return 'this is my string';
}
$f= 'asdf';
echo "Hello {$f()}\n";
?>
answered Nov 19, 2009 at 5:06

2 Comments

Sorry, no this does not work. The braces can only contain a $ variable reference such as multiply dimensioned arrays.
My first example wasn't quite right - but it is possible to call functions from within strings.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.