davidf85 Posted February 18, 2012 Share Posted February 18, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257238-php-and-html/ Share on other sites More sharing options...
litebearer Posted February 18, 2012 Share Posted February 18, 2012 are you naming the page something.php? Quote Link to comment https://forums.phpfreaks.com/topic/257238-php-and-html/#findComment-1318574 Share on other sites More sharing options...
davidf85 Posted February 18, 2012 Author Share Posted February 18, 2012 Yes. Placing php code at the top works fine. But within the HTML the page becomes void. Quote Link to comment https://forums.phpfreaks.com/topic/257238-php-and-html/#findComment-1318578 Share on other sites More sharing options...
davidf85 Posted February 18, 2012 Author Share Posted February 18, 2012 <?php session_start(); ?> <body> <div> etc etc php will not work within these lines. </div> </body> Quote Link to comment https://forums.phpfreaks.com/topic/257238-php-and-html/#findComment-1318579 Share on other sites More sharing options...
Anon-e-mouse Posted February 18, 2012 Share Posted February 18, 2012 <?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? Quote Link to comment https://forums.phpfreaks.com/topic/257238-php-and-html/#findComment-1318580 Share on other sites More sharing options...
davidf85 Posted February 18, 2012 Author Share Posted February 18, 2012 I was not surrounding the code with tags I as thinking I could freely write HTML within PHP tags. Quote Link to comment https://forums.phpfreaks.com/topic/257238-php-and-html/#findComment-1318581 Share on other sites More sharing options...
Anon-e-mouse Posted February 18, 2012 Share Posted February 18, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257238-php-and-html/#findComment-1318582 Share on other sites More sharing options...
davidf85 Posted February 18, 2012 Author Share Posted February 18, 2012 Can I use <? ?> to enclose code? Quote Link to comment https://forums.phpfreaks.com/topic/257238-php-and-html/#findComment-1318590 Share on other sites More sharing options...
Anon-e-mouse Posted February 18, 2012 Share Posted February 18, 2012 Can I use <? ?> to enclose code? You may use the short codes.. But! They need to be enabled as per example 2: http://www.php.net/manual/en/language.basic-syntax.phpmode.php Quote Link to comment https://forums.phpfreaks.com/topic/257238-php-and-html/#findComment-1318592 Share on other sites More sharing options...
Pikachu2000 Posted February 18, 2012 Share Posted February 18, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/257238-php-and-html/#findComment-1318697 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.