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 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    33
    Thanks
    6
    Thanked 0 Times in 0 Posts

    PHP variables and HTML

    Is there a way to just not let php be executed and let it stand as text in a variable? For instance this is what I'm doing:

    PHP Code:
    $blah "<li class="blah" if(empty($row['a1'])) {
       echo 'style=\"display:none;\"'; 

    if (isset($row['a1'])) {
       echo ' ';
    } > Blah blah blah </li> 
    It comes back with an error:

    PHP Code:
    Parse errorsyntax errorunexpected T_ENCAPSED_AND_WHITESPACEexpecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/46/sdgsdg/htdocs/bah/blahblah.php on line 232 
    which is that line...

    Anyone know?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,512
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    A bunch of different ways to do it ... this is just one of many ...

    PHP Code:

    $style
    ="display:visible;";
    if(empty(
    $row['a1'])){
    $style="display:none;";
    }
    echo 
    "<li class=\"blah\" style=\"$style\" > blah blah blah </li>"
    Last edited by mlseim; 01-12-2010 at 07:08 PM.

  • Users who have thanked mlseim for this post:

    Joemoemofo (01-12-2010)

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Heredoc perhaps?
    You could also use single quotes around the text, or escape the " inside the text with a \
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #4
    New Coder
    Join Date
    Jan 2009
    Posts
    33
    Thanks
    6
    Thanked 0 Times in 0 Posts
    @mlseim

    Thanks! I just wasn't thinking straight for some reason with putting if statements in variables ha. You brought simplicity to my attention and helped me sincerely. Appreciate it!

    @jay

    thanks


  •  

    Posting Permissions

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