Prevent variable expansion in heredoc

Discussion in 'PHP' started by abdussamad, Jan 24, 2008.

  1. #1
    Hi

    I have some advertising js code that I want to put into a php variable for inclusion in my site. The code goes something like this:

    
    $_ad_Code=<<<ADC
    
    blahdibhal dljfdlkf$jump dkhfdkd
    
    ADC;
    
    
    Code (php):
    The $jump in the heredoc above is not related to php but a part of the js ad code. Now the problem I am faced is that php is trying to expand $jump and generating error messages as a result. I don't want it to expand $jump but just display it literally (leave it to the client's browser to interpret). How do I prevent php from expanding $jump? I tried escaping it with a \ just before $jump but it does not work.


    Thanks
    Abdussamad
     
    abdussamad, Jan 24, 2008 IP
  2. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Put it in single-quotes. The variables will not be expanded.

    Like this:
    $ad_code = ' some text here $i_will_not_be_expanded';
     
    tamen, Jan 24, 2008 IP
  3. sharqi

    sharqi Guest

    Messages:
    105
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    sharqi, Jan 25, 2008 IP
  4. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #4
    You will need to escape the dollar sign.
    
    $_ad_Code=<<<ADC
    
    blahdibhal dljfdlkf\$jump dkhfdkd
    
    ADC;
    
    PHP:
     
    Kaizoku, Jan 25, 2008 IP