PHP

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • heredoc question

    5 answers - 625 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    How can I include "place holders" for variables in a heredoc such that after the heredoc is declared, I can assign the
    variables?
    I have a config file with a heredoc string declared. I'd like to keep the include config.inc at the top of my page.
    Down in the page, when I call the heredoc variable, I'd like to replace the "place holders" with a values assigned in
    the page, below the include statement.
    I know I can break up the heredoc into several segments and put the variables between them; but, I rather not.
    Seems like there should be an obvious way to do this.
    Thanks
  • No.1 | | 943 bytes | |

    At 07:40 AM 5/5/2006, Al wrote:
    >How can I include "place holders" for variables in a heredoc such
    >that after the heredoc is declared, I can assign the variables?


    Al,

    Escape the $'s in your heredoc expression so that the variable names
    remain and aren't evaluated, then eval() the whole expression later:

    $sString = <<< hdBodyClass
    <body class="\$sBodyClass">
    hdBodyClass;

    This sets $sString equal to:

    <body class="$sBodyClass">

    Then:
    $sBodyClass = "contact";
    eval("\$sHTML = '$sString';");

    Evaluates as:

    $sHTML = '<body class="contact">';

    As always, be careful not to include any external data in an eval()
    statement without careful sponging. Its presence in your script
    should be regarded as an Achilles heel and treated with special respect.

    Paul
  • No.2 | | 686 bytes | |

    Fri, 2006-05-05 at 10:40, Al wrote:
    How can I include "place holders" for variables in a heredoc such that after the heredoc is declared, I can assign the
    variables?

    I have a config file with a heredoc string declared. I'd like to keep the include config.inc at the top of my page.

    Down in the page, when I call the heredoc variable, I'd like to replace the "place holders" with a values assigned in
    the page, below the include statement.

    I know I can break up the heredoc into several segments and put the variables between them; but, I rather not.

    Seems like there should be an obvious way to do this.

    str_replace() ?

    Rob.
  • No.3 | | 764 bytes | |

    just use str_replace

    05/05/06, John Nichel <john (AT) kegworks (DOT) comwrote:

    Al wrote:
    How can I include "place holders" for variables in a heredoc such that
    after the heredoc is declared, I can assign the variables?

    I have a config file with a heredoc string declared. I'd like to keep
    the include config.inc at the top of my page.

    Down in the page, when I call the heredoc variable, I'd like to replace
    the "place holders" with a values assigned in the page, below the
    include statement.

    I know I can break up the heredoc into several segments and put the
    variables between them; but, I rather not.

    Seems like there should be an obvious way to do this.

    Thanks
    --
    printf()?
  • No.4 | | 1044 bytes | |

    Robert Cummings wrote:
    Fri, 2006-05-05 at 10:40, Al wrote:
    >How can I include "place holders" for variables in a heredoc such that after the heredoc is declared, I can assign the
    >variables?
    >>

    >I have a config file with a heredoc string declared. I'd like to keep the include config.inc at the top of my page.
    >>

    >Down in the page, when I call the heredoc variable, I'd like to replace the "place holders" with a values assigned in
    >the page, below the include statement.
    >>

    >I know I can break up the heredoc into several segments and put the variables between them; but, I rather not.
    >>

    >Seems like there should be an obvious way to do this.


    str_replace() ?

    Rob.

    Yes, that is the simplest solution. Now that you've refreshed my memory, I've done it that way in the past.

    Thanks
  • No.5 | | 664 bytes | |

    Al wrote:
    How can I include "place holders" for variables in a heredoc such that
    after the heredoc is declared, I can assign the variables?

    I have a config file with a heredoc string declared. I'd like to keep
    the include config.inc at the top of my page.

    Down in the page, when I call the heredoc variable, I'd like to replace
    the "place holders" with a values assigned in the page, below the
    include statement.

    I know I can break up the heredoc into several segments and put the
    variables between them; but, I rather not.

    Seems like there should be an obvious way to do this.

    Thanks

    printf()?

Re: heredoc question


max 4000 letters.
Your nickname that display:
In order to stop the spam: 2 + 1 =
QUESTION ON "PHP"

EMSDN.COM