Reputation: 9549
I want to put some procedural stuff like html in a variable;
Normally we do this:
<?php
$my_var = '
<h1>some header</h1>
some text.
';
?>
Now I want it to look like this:
<?php
$my_var = '
?>
<h1>some header</h1>
some text.
<?php
';
?>
So that we open a php code, declare a variable, do some stuff outside php, and then reopen php code and close the var and we get that stuff that is outside php, we get it inside that variable.
Thanks.
Upvotes: 0
Views: 114
Reputation: 1219
Please check php heredoc
http://php.net/manual/en/language.types.string.php
Hope it helps
Upvotes: 1
Reputation: 939
i don't think there is a way because php ignores lines outside the php tags. if u have the php in a other file user file_get_contents
Upvotes: 1
Reputation: 10557
<?php
ob_start();
?>
<h1>some header</h1>
some text.
<?php
$my_var = ob_get_contents();
ob_end_clean();
echo my_var;
?>
Upvotes: 6