+ Reply to Thread
Results 1 to 4 of 4

Thread: PHP creating HTML

  1. #1
    bardman is offline x10Hosting Member bardman is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    2

    PHP creating HTML

    Hi people,

    NOOB ALERT ! :dunno:

    After reading ways of writing more secure interfaces for websites I came across the universal index.php code and includes.

    However, is there an easier/quicker way to get a php include to create an HTML front, other than copying the wanted output into the include and surrounding each and every line manually with echo's such as ...

    echo '------ html this ------';
    echo '------ html that ------';

    Looking to save my poor fingers ... lol

    Many thanks

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: PHP creating HTML

    Escaping tags will work too:

    Code:
    <?php
    if ($var == true) {
    ?>
    <html>
    blah blah blah
    <? php
    }
    ?>
    You can also include php files that have no php tags at all. This is helpful if you have something that is the same on every single page, like a header or footer:

    Code:
    header.php
    <div id="header>
    This is my header
    </div>
    
    index.php
    <?php
    include("header.php");
    ?>
    This will output the contents of header.php as soon as the file is included.

    One more thing you can do is use double quotes, as double quotes keep newline and tab characters intact, whereas single quotes ignore these:
    Code:
    <?php
    echo "<html>
    this is my code blah blah
    blah
              blah
                    blah
    etc";
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    bardman is offline x10Hosting Member bardman is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    2

    Re: PHP creating HTML

    Thanks for the code Garrett

    *darn it, should've realised the first one* :nuts:

    I assume the header example works similar for a common NavBar type (down the left-side of the page) just div it with left adjustment etc

    Onwards and erm, slightly forwards lol

  4. #4
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: PHP creating HTML

    You're welcome

    Let me know if you have any more questions.
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

+ Reply to Thread

Similar Threads

  1. Problems with Apache parsing html as php
    By hezuo in forum Programming Help
    Replies: 6
    Last Post: 01-29-2009, 10:21 AM
  2. Replies: 5
    Last Post: 01-26-2009, 10:03 AM
  3. Replies: 1
    Last Post: 05-08-2008, 04:40 PM
  4. Replies: 3
    Last Post: 03-10-2008, 12:22 PM
  5. RSS to HTML PHP Script (FREE)
    By unmanaged in forum Scripts & 3rd Party Apps
    Replies: 6
    Last Post: 02-21-2008, 04:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers