Results 1 to 10 of 10

Thread: Band new to PHP

  1. #1
    Join Date
    Feb 2009
    Posts
    159
    Thanks
    60
    Thanked 3 Times in 3 Posts

    Red face Band new to PHP

    I have not ever used PHP before and I am tring to figure out how to use html inside a php document. Not only do I need to know how to include html coding inside a php document but I need to know how do I refure to the PHP document it in my html document once I have it created?

    Thanks.
    Last edited by robin9000; 02-02-2009 at 07:38 PM.

  2. #2
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

  3. #3
    Join Date
    Feb 2009
    Posts
    159
    Thanks
    60
    Thanked 3 Times in 3 Posts

    Default

    Thanks for the links but the first dose not work and really all am looking for is just to know the begining tag and ending tag I need to use so that I can use html inside the PHP document.

    Then I just need to know if it's the header or body where I link to the php document in my html file and what the tags are?
    Last edited by robin9000; 02-02-2009 at 06:11 PM. Reason: fix senctence

  4. #4
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    You can use PHP inside HTML, but you just have to save the file as .php, like so:

    Code:
    <?php 
    $title = "My page";
    ?>
    <html>
    
    <head>
    <title><?php echo $title ?></title>
    </head>
    
    <body>
    
    </body>
    
    </html>
    This would print out "My page" as the page's title.

    To start the PHP tags you put <?php and to end them you type ?>

    You can integrate these anywhere within your document.

    Edit: Also, good tutorials there Snookerman, thanks.

  5. #5
    Join Date
    Feb 2009
    Posts
    159
    Thanks
    60
    Thanked 3 Times in 3 Posts

    Default

    No, no no. Mabye I did not say it right. I want to do the oposite of that. I want to use HTML inside a PHP file Then I want to incorporate the external PHP document into my HTML documents.

    I was told it was possible, I just don't know how?

    I know maybe it sounds wird but I have a good reason for wanting to do this.

  6. #6
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Oh right sorry,

    To be able to include php on HTML pages you still need to save that HTML file as .php to be able to include the file. It would be like this:

    mypage.php
    Code:
    <html>
    
    <head>
    
    </head>
    
    <body>
    <?php include("header") ?>
    </body>
    
    </html>
    header.php:

    PHP Code:
    <?php

    echo "I am a header, I can be included across multiple pages, all your base are belong to us";

    ?>
    As far as I know you cannot include a PHP file into an HTML file, as HTML can't read PHP, so you need to save the initial HTML file as .php as well.

  7. The Following User Says Thank You to Schmoopy For This Useful Post:

    robin9000 (02-02-2009)

  8. #7
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    2,023
    Thanks
    17
    Thanked 319 Times in 318 Posts
    Blog Entries
    3

    Default

    You can use include or require for that. The tutorials I posted deal with that pretty well:
    http://blog.themeforest.net/tutorials/diving-into-php-day-6/
    http://devzone.zend.com/node/view/id/636#Heading7

    Good luck!

  9. #8
    Join Date
    Feb 2009
    Posts
    159
    Thanks
    60
    Thanked 3 Times in 3 Posts

    Default

    Maybe it's just me, so I will try to make it clear as to what I am trying to do.

    I want to create a PHP file and include the following coding into the php file:



    <div id="myslidemenu" class="jqueryslidemenu">
    <ul>
    <li><a href="http://www.dynamicdrive.com">Communications</a></li>
    <!--Single row-->
    <li><a href="#">Home</a>
    <ul>
    <li><a href="#">Location</a></li>
    <li><a href="#">Disclaimer</a></li>
    <li><a href="#">Contact Us</a></li>
    <li><a href="#">F.A.Q.</a></li>
    </ul>
    </li>
    <!--text-->

    <li><a href="#">Services</a>
    <ul>
    <li><a href="#">WebDesign</a></li>
    <li><a href="#">Computer</a>
    <ul>
    <li><a href="#">Sub Item 2.1.1</a></li>
    <li><a href="#">Sub Item 2.1.2</a></li>
    <li><a href="#">Folder 3.1.1</a>
    <ul>
    <li><a href="#">Sub Item 3.1.1.1</a></li>
    <li><a href="#">Sub Item 3.1.1.2</a></li>
    <li><a href="#">Sub Item 3.1.1.3</a></li>
    <li><a href="#">Sub Item 3.1.1.4</a></li>
    <li><a href="#">Sub Item 3.1.1.5</a></li>
    </ul>
    </li>
    <li><a href="#">Sub Item 2.1.4</a></li>
    </ul>
    </li>
    </ul>
    </li>
    <li><a href="http://www.dynamicdrive.com/style/">Item 4</a></li>
    </ul>
    <br style="clear: left" />
    </div>



    Then I want to save that PHP file and I want to use it in my Html pages as the external PHP file witch it now is.

    Please be pationte with me as I am knew to this and maybe I am not understanding everthing your telling me.

    Thanks.

  10. #9
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Yes, I understand what you mean, but the file you include the PHP file with must be php as well. You can't include a php file in a normal HTML file. Do the following:

    1. Save the following code to a php file called menu.php

    PHP Code:
    <?php 
    echo "<div id=\"myslidemenu\" class=\"jqueryslidemenu\">
    <ul>
    <li><a href=\"http://www.dynamicdrive.com\">Communications</a></li>
    <!--Single row-->
    <li><a href=\"#\">Home</a>
    <ul>
    <li><a href=\"#\">Location</a></li>
    <li><a href=\"#\">Disclaimer</a></li>
    <li><a href=\"#\">Contact Us</a></li>
    <li><a href=\"#\">F.A.Q.</a></li>
    </ul>
    </li>
    <!--text-->

    <li><a href=\"#\">Services</a>
    <ul>
    <li><a href=\"#\">WebDesign</a></li>
    <li><a href=\"#\">Computer</a>
    <ul>
    <li><a href=\"#\">Sub Item 2.1.1</a></li>
    <li><a href=\"#\">Sub Item 2.1.2</a></li>
    <li><a href=\"#\">Folder 3.1.1</a>
    <ul>
    <li><a href=\"#\">Sub Item 3.1.1.1</a></li>
    <li><a href=\"#\">Sub Item 3.1.1.2</a></li>
    <li><a href=\"#\">Sub Item 3.1.1.3</a></li>
    <li><a href=\"#\">Sub Item 3.1.1.4</a></li>
    <li><a href=\"#\">Sub Item 3.1.1.5</a></li>
    </ul>
    </li>
    <li><a href=\"#\">Sub Item 2.1.4</a></li>
    </ul>
    </li>
    </ul>
    </li>
    <li><a href=\"http://www.dynamicdrive.com/style/\">Item 4</a></li>
    </ul>
    <br style=\"clear: left\" />
    </div>"
    ;

    ?>
    2. Rename your current HTML file to have the extension .php instead of HTML. Example: index.html ---> index.php, you don't have to change anything else, just rename the file index.php

    3. Put the include somewhere in index.php where you want the menu to be.

    Code:
    <html>
    <head>
    <title>My Page</title>
    </head>
    
    <body>
    
    <div id="header">Welcome to my site</div>
    <div id="menu"> // Include the menu in this div
    <?php
    include("menu.php");
    ?>
    </div>
    
    
    </body>
    
    </html>
    Just test that out, obviously the divs I made there aren't going to be the same on your page, but it was just to give you an idea.

    You can then implement the same menu.php in different pages.

    Hope that helps.
    Last edited by Schmoopy; 02-02-2009 at 07:34 PM. Reason: Forgot to escape quotes

  11. The Following User Says Thank You to Schmoopy For This Useful Post:

    robin9000 (02-02-2009)

  12. #10
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Just to clarify what Schmoopy said, you CAN include an .html file inside of a .php file.

    But you CANNOT use include() or any other php functions inside of a file with any extension other than .php .

    So:

    PHP Code:
    <?php

    include('menu.html'); // could be menu.txt, menu.inc, etc.

    ?>
    is fine.

    But,

    HTML Code:
    <--! this is a file with a .html extenstion -->
    
    include('file.php');
    Won't work.

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
  •