Question:

I am creating a website using both php and html. is this true- you can put html in php? can u put php in html?

by  |  earlier

0 LIKES UnLike

I am creating a website using both php and html. is this true- you can put html in php? can u put php in html? Also how do i put php in php like this right- html <? php ?> html If I do this it won't show my php or my html!!! Help!

 Tags:

   Report

3 ANSWERS


  1. It&#039;s saved as a .php file? And Apache is running on the server?


  2. save below code with .php extension not .html

    &lt;HTML&gt;

    &lt;HEAD&gt;

      &lt;TITLE&gt; New Document &lt;/TITLE&gt;

      

    &lt;/HEAD&gt;

    &lt;?php $name1=&quot;any_name&quot;; $sal=&quot;55000&quot;; ?&gt;

    &lt;BODY&gt;

      &lt;table&gt;

    &lt;tr&gt;

    &lt;td&gt;this is your name= &lt;?=$name?&gt;&lt;/td&gt;

    &lt;/tr&gt;

    &lt;tr&gt;

    &lt;td&gt;Your salary= &lt;?=$sal?&gt; &lt;/td&gt;

    &lt;/tr&gt;

    &lt;/table&gt;

    &lt;/BODY&gt;

    &lt;/HTML&gt;


  3. example:  your site.php

    &lt;html&gt;

    &lt;head&gt;&lt;title&gt;yoursite&lt;/title&gt;&lt;/head&gt;

    &lt;body&gt;

    &lt;h1&gt;Hi, welcome to mysite&lt;/h1&gt;

    &lt;p&gt;this is a paragraph&lt;/p&gt;

    &lt;?php

         if(something)

         {

    ?&gt;

    HTML to be executed by if statement

    &lt;?php

         }

    ?&gt;

    &lt;?php

    // alternative way to embed stuff in php

         echo &#039;any text&#039;

         echo $varialbe

    ?&gt;

    &lt;/body&gt;

    &lt;/html&gt;

    If you are writing this site on your computer it helps to have a server capable of php inorder to be able to view it.  WAMP server is a nice piece of software for developing websites on your computer.  Also, instead of using &lt;?php to for you starting php tag you can use short php tags.  Instead of

    &lt;?php

         $variable = &#039;random text&#039;

         echo $variable

    ?&gt;

    you could write

    &lt;?php

         $varialble  // some variable that you previously defined

    ?&gt;

    and reference it later with a short tag

    &lt;?= $varialbe ?&gt;

    this would echo the text stored in $varialbe without typing &lt;?php and echo.

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions