Jump to content

php and html


davidf85

Recommended Posts

I am writing a shopping cart, and so far I have made the page in html, only a very simple front end with a logo a couple of links and a template for the items.

I am trying to add the <?php and ?> tags to the page but when I try and view the page in IE it comes blank.

If I add

<?php

 

echo HELLO;

 

?> 

to the top of the page, above all the HTML it works. but not when I enclose the entire page... even though there is no php coding on the page.

 

Link to comment
https://forums.phpfreaks.com/topic/257238-php-and-html/
Share on other sites

<?php

session_start();

?>

 

<body>

<div>

etc etc      php will not work within these lines.

 

</div>

</body>

 

Hi David,

 

As long as you surround the code in php tags then it should work fine for example:

 

<div>
<?php echo "Hello world."; ?>
</div>

 

Works fine on my server? Are you receiving any errors on screen?

 

Link to comment
https://forums.phpfreaks.com/topic/257238-php-and-html/#findComment-1318580
Share on other sites

I was not surrounding the code with tags I as thinking I could freely write HTML

within PHP tags.

 

In short no.

 

But! If you want to write HTML within a PHP echo for example you can but you must surround any PHP in the correct tags such as:

 

<?php echo '<p style="color:green">Hello World!</p>'; ?>

 

Just remember that PHP must always be within its own tags even when writing HTML within it.

 

Hope it helps.

Link to comment
https://forums.phpfreaks.com/topic/257238-php-and-html/#findComment-1318582
Share on other sites

Using short tags makes your code less portable. The short_open_tag directive is OFF by default, and if you need to use your code on a server where you don't have access to the php.ini file, you're going to end up doing a search/replace and changing them all anyhow. So, why not just type the extra 3 characters to begin with?

Link to comment
https://forums.phpfreaks.com/topic/257238-php-and-html/#findComment-1318697
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.