HTML Code in PHP

Status
Not open for further replies.

mediator

Technomancer
Thats easy! U have 2 options
Let me give u an example with <a href...> thing!

1. : Parting the Php block
Code:
<?php
{
//code...php block initiated
?>
[b]<a href="mediator_is_great.htm">meds</a>[/b]
<?php
//code php block completed
}
?>

2. : In one go!
Code:
<?php
$link="mediator_is_great.html";
$name="meds";
echo "[b]<a href=\"$link\">$name</a>[/b]";
?>

Like wise to mark something bold we have
Code:
<?php
echo "<b>mediator is cool</b>";
?>
Ur Problem Solved!
 
Last edited:

ahref

In the zone
Although mediator has explained clearly. Let me add my two cents
Server will treat everything outside <?php ?> tags as html.
If you want to add any html tag in php script then use eithter echo or print command like
<?php
print "<h1>Hello World</h1>";
?>
 

tuxfan

Technomancer
My further 1 cent in addition to ahref's 2 cents ;)

Its not the server that treats PHP, its the PHP interpreter that does the job!! Here's the over-simplified sequence.
  1. A browser sends a request for a file to the server.
  2. If its .php file, Apache calls in PHP interpreter for help and hands over the file to it.
  3. PHP interpreter goes thru the file and processes everything thats within <?php and ?> tags. However, it doesn't do anything to the code thats outside those tags.
  4. Apache once again takes over the output give by the interpreter and hands it over to the browser which is dumb enough to understand only HTML and Javascript.
  5. If the browser is IE, it will render even a W3 standard compliant page erroneously. If the browser is not IE, it is more likely that the page is rendered correctly :D
I would also like to point out that PHP can be used anywhere on the page whether it be <head> or <title> or whatever!! For example, based on certain criterion, it can even me made to select a differnt external CSS files or change the title of the page. Here's a small simple example.

PHP:
<html>
  <head>
    <title>
      <?php
        $myid = $_GET["identity"];
        if ($myid == "one")
          print("This is the my favourite page tite");
         else
          print("This is the default page title");
      ?>
    </title>
  </head>
  <body>
  </body>
</html>
So start thinking a little differently. You can use break-away from static code anywhere with just the <?php and ?> tags. All that you need is .php extension to the file.
 
Last edited:

[xubz]

"The Cake is a Lie!!"
Guys, its better if you use PHP BBCode Tag..

PHP:
<html>
  <body>
    <b>
    <?php
       $a=1;
       $b=2;
       if($a==$b) {
          echo "Bull5hit!";
       } else {
          die("Yay!");
       }
     ?>
     </b>
  </body>
</html>
 

tuxfan

Technomancer
subbzzz said:
Guys, its better if you use PHP BBCode Tag..

At first, I didn't understand what you are saying! But then found out that you are right. You are talking about the php tag for posting in the forum. The tag makes the PHP code more readable on the forum :) and its nothing to do with the php tag in HTML pages.
 
Status
Not open for further replies.
Top Bottom