Problem with PHP spaces

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swethak
    New Member
    • May 2008
    • 118

    Problem with PHP spaces

    Hi,

    I am getting the problem when i used the php code inside javascript. i,e

    Code:
    <?
    $description=<p><strong>This is Test1</strong></p><p><strong>This is Test2</strong></p>
    ?>
    <script>
    alert('<?=$description?>');
    </script>
    Above code works fine and give the alert message when page will loaded.

    i have modified that above code like that

    Code:
    <?
    $description=<p><strong>This is Test1</strong></p>
    <p><strong>This is Test2</strong></p>
    ?>
    <script>
    alert('<?=$description?>');
    </script>
    It didn't worked and didn't give any alert message. Anybody Could please tell the solution to my problem.




    Thanks
    Swetha
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by swethak
    Code:
    <?
    $description=<p><strong>This is Test1</strong></p><p><strong>This is Test2</strong></p>
    ?>
    <script>
    alert('<?=$description?>');
    </script>
    Above code works fine and give the alert message when page will loaded.
    I'd expected a warning at least (usually strings are enclosed in
    ' or ")

    Comment

    • swethak
      New Member
      • May 2008
      • 118

      #3
      Hi



      Thank you very much for your reply. I have used like this

      Code:
      <?php
      $description='<p><strong>This is Test1</strong></p>
      <p><strong>This is Test2</strong></p>';
      ?>
      <script>
      alert('<?=$description?>');
      </script>
      in that actually i am getting the description from database 'text' data type . For getting clear idea i mentioned like that.
      Have an idea could you please tell the solution.


      Thanks
      Swetha

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        do you have short tag turned on? if not <?= will not work, do <?php echo ...


        Dan

        Comment

        Working...