I use PHP’s EOF string to format HTML content without the hassle of having to escape quotes etc. How can I use the function inside this string?
<?php
$str = <<<EOF
<p>Hello</p>
<p><?= _("World"); ?></p>
EOF;
echo $str;
?>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As far as I can see in the manual, it is not possible to call functions inside HEREDOC strings. A cumbersome way would be to prepare the words beforehand:
a workaround idea that comes to mind is building a class with a magic getter method.
You would declare a class like this:
Initialize an object of the class at some point:
You can then use the following syntax to do a gettext lookup inside a HEREDOC block:
$translate->Worldwill automatically be translated to the gettext lookup thanks to the magic getter method.To use this method for words with spaces or special characters (e.g. a gettext entry named
Hello World!!!!!!, you will have to use the following notation:This is all untested but should work.