0

i have searched a lot and still no chance, is there a way for calling a php function inside echo HTML ?

i also tried this and not worked.

<?php

echo <<<HTML

[HTML PARTS..]

<td colspan="2">its function: <? $z = func($x); echo $z; ?> </td>

...

HTML;

?>

function works outside of html.

3
  • Have you considered using a template engine? Commented May 26, 2012 at 13:06
  • yes (if i get ur mean) DreamWeaver, and phpstorm for coding.. Commented May 26, 2012 at 13:45
  • That's an editor, not a template engine... Commented May 26, 2012 at 13:48

4 Answers 4

3

You need to do:

<?php
$z = func($x);
echo <<<HTML

[HTML PARTS..]

<td colspan="2">its function: {$z} </td>

...

HTML;

?>

Or you could just not use heredoc:

<?php
// your php code
?>

[HTML PARTS..]

<td colspan="2">its function: <? $z = func($x); echo $z; ?> </td>

...

<?php
// your php code
?>
Sign up to request clarification or add additional context in comments.

Comments

1

Nope. You can insert variables as per usual, so you'll need to calculate this before hand.

Comments

0

Echoed text isn't evaluated. To interpret "stringed" code you'd need eval, although it's a very deprecated command, since it's dangerous.

A better option would be to concatenate the result of those function calls to the HTML.

Comments

0

Nope. Results need to be calculated beforehand. Only variables get parsed

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.