function in hereDocs

Posted on 2016-11-07
Last Modified: 2016-11-08
Is it possible to call a function from inside a heredoc?

For example, if I wanted to call date('Y-m-d', $rwTrans['dateTime']) inside the heredoc:-
    echo <<<EOD
      <tr data-transID="{$rwTrans['transID']}">
        <td>{date('Y-m-d', $rwTrans['dateTime'])}</td>

Open in new window

Any ideas?
Question by:tonelm54
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 110

Accepted Solution

Ray Paseur earned 500 total points
ID: 41877985
It doesn't work that way.  You get variable substitution in HEREDOC, but not function calls.  So call the function outside of the HEREDOC, set a variable, and use the variable in the HEREDOC block.  Something like this...
    $datexxx = date('Y-m-d', $rwTrans['dateTime']);
    echo <<<EOD
      <tr data-transID="{$rwTrans['transID']}">

Open in new window


Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Link failure 16 70
PHP SMTP authentication 6 28
JSON decode 5 21
P3P validator , ASP, PHP ,Https and Http links 3 13
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question