Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setting HTML Code as a Variable

    I am simply trying to set a variable which contains HTML code.

    To use
    $var = "image"
    is fine but when you get to
    $var = "<img scr="image.gif" alt="image">"
    etc. etc. I start getting errors.

    Is there a special way to set a large HTML sement to a variable?
    eTheory - the theory of revolution

  • #2
    Regular Coder
    Join Date
    Oct 2002
    Posts
    380
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your problem there is that you haven't escaped the quotes. There are two ways to do it:
    PHP Code:
    $var "<img scr=\"image.gif\" alt=\"image\">"
    $var "<img scr='image.gif' alt='image'>" 

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great, cheers, shoulda known that one

    Thanks
    eTheory - the theory of revolution

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,095
    Thanks
    11
    Thanked 101 Times in 99 Posts
    ...3 ways

    PHP Code:
    <?
    $var 
    '<img scr="image.gif" alt="image">';
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    Registered User
    Join Date
    Feb 2003
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Heredoc string quoting

    Hey,

    Check http://www.php.net/manual/en/language.types.string.php for Heredoc string quoting.

    It is useful to store large quantities of HTML in a variable without worrying about escaping quotes etc.

    Jesh


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •