SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Embeding html into php

    Hello all I have a quick question. Is it possible and if so how, to embed html into php? By that I mean something like this:

    Code:
    <?php if (some condition) { ?>
    my html here
    <?php } ?>
    I know that, the above works perfectly fine but I dont see how or if its possible to do the same thing with an if else statement. I always seem to get syntax errors :s

    Thanks for the help

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,998
    Mentioned
    100 Post(s)
    Tagged
    0 Thread(s)
    Give this a try
    PHP Code:
    if (some condition) {
    echo 
    "<my html here>";

    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah the only problem is that I have a bit more code I need to include. Im modifying my wordpress layout with some extra conditions.

    Code:
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    I need to include that in an if else statement. Can I just echo the html and then concatenate the php to it wherever its required?

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php if (some condition) { ?>
    my html here
    <?php } else { ?>
    other html here
    <?php  ?>
    Also
    http://www.php.net/manual/en/control...ive-syntax.php

  5. #5
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for that..and for the link. I was unaware that there was an alternative..I saw that quite frequently in the code and never understood it.

  6. #6
    SitePoint Member
    Join Date
    Dec 2008
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML designers want programmers to code out of PHP code, to see the source in editors like Dreamviewer.

    Also. Doing an echo "<div>"; is more expensive than ?><div><?
    so it's better to use out of PHP code.

    But sometimes otherwise is better. Depends on your needs.


Bookmarks

Posting Permissions

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