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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.