html code in php

embedd an html code including the style on a php. can it be done?

Page 1 of 1

7 Replies - 2577 Views - Last Post: 07 April 2009 - 12:21 AM Rate Topic: -----

#1 mobius19   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 43
  • Joined: 26-November 08

html code in php

Post icon  Posted 06 April 2009 - 10:01 AM

hello everyone I have read in a thread that you can embedd an html tag on a php. like what spearfish said:
<?php
echo "<html><head><title>Hello World!</title></head>";
echo "<body><p>This is HTML created from php!</p></body></html>";
?>



This can be done. But my question is, can we also call on the style of that html tag like:

<?php
echo "<html><head><title>Hello World!</title>[b]<style type="text/css> style etc </style> or <link rel="style/css" href="style.css  rel="stylesheet"[/b] /></head>";
echo "<body><p>This is HTML created from php!</p></body></html>";
?>



Can that be done? Im doing this because my form which is in php when embedded in html, is not sending the info on my mail.So il be trying to reverse it, so that it may work. i hope. It has been great to be here and exchange information. Thanks guys in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: html code in php

#2 RPGonzo   User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: html code in php

Posted 06 April 2009 - 10:40 AM

Im not sure about importing the style sheet with a reference tag like that unless the css file was sent along with the email.. i use the HTML email thru php but hard code the styles

$styles = '<html><head><style type="text/css">
					body { width: 750px; height: 750px; margin: 0px;}
					b { width: 175px; margin: 0; padding: 0; margin-bottom: 10px; text-align: left; color: #00305E; }
					p { background-color: #EFEFE4; border: 1px solid #666666; width: 90%; padding: 0; margin: 0; 																margin-bottom: 10px; }
					h1 { color: #00305E; text-align: left; margin-top: 20px; margin-bottom: 10px; }
					td { width: 350px; }
					.code { font-size: 14px; color: #FF0000; }
					</style></head><body>';





As well if your doing this for email there are certain style properties not supported in certain email providers. I found this out the hard way.
Was This Post Helpful? 0
  • +
  • -

#3 sl4ck3r   User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 285
  • Joined: 22-September 07

Re: html code in php

Posted 06 April 2009 - 01:01 PM

I'm not sure about the whole email thing (not that i see you mailing anything in that code), but php executes before the page is sent to the client. basically you could make the whole page echoed if you want it doesn't really matter. When the page is sent to the user it will not have any php in it. All of it has already been done. That being said, what you have will not work because you need to escape quotes or use single quotes to do that. Examples:

<?php
   echo '<link href="style.css" rel="stylesheet" type="text/css" />'
?>


or
<?php
   echo "<link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\" />"
?>



Learn more about echo here:
http://www.tizag.com/phpT/echo.php

This post has been edited by sl4ck3r: 06 April 2009 - 01:03 PM

Was This Post Helpful? 0
  • +
  • -

#4 grimpirate   User is offline

  • Pirate King
  • member icon

Reputation: 149
  • View blog
  • Posts: 717
  • Joined: 03-August 06

Re: html code in php

Posted 06 April 2009 - 02:15 PM

You can edit anything on an HTML page with PHP mobius19. Be it embedded style information or javascript or title tags or meta tags, etc. PHP basically can create any and all data that is output to your browser.
Was This Post Helpful? 0
  • +
  • -

#5 c0mrade   User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 412
  • Joined: 16-November 07

Re: html code in php

Posted 06 April 2009 - 04:32 PM

Posted Image

Ok, ok :)

Why do you want to echo html from php?

All PHP does is get ran before the html page is sent to the browser, anything that you echo from PHP code will simply become part of the html page.

So this:
<html>
<blah>
<?php echo 'hello world'; ?>
</blah>
</html>



Is exactly the same as this:
<html>
<blah>
hello world
</blah>
</html>



so to make it more relevant...

Your original code:
<?php
echo "<html><head><title>Hello World!</title></head>";
echo "<body><p>This is HTML created from php!</p></body></html>";
?>



Is exactly the same as:
<html><head><title>Hello World!</title></head>
<body><p>This is HTML created from php!</p></body></html>


Was This Post Helpful? 0
  • +
  • -

#6 mobius19   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 43
  • Joined: 26-November 08

Re: html code in php

Posted 06 April 2009 - 06:20 PM

I'm sorry for the trouble for all you guys that i may be causing.. It's just my form which is in php code is inside my html page is not sending the infos. on my email. I'm suspecting it's because the bind between html and php coding that i may be doing wrong. or another question,would a php code inside a div tag will work? eg.
<div id="container">
<? code code.. ?>
<form action="process.php" method="post"
tables etc...
</form>
</div>



Though on my page it is saying message was successfully sent but im not getting it on my mail.I also chmod my file to 777.oh men i'm lost..
Was This Post Helpful? 0
  • +
  • -

#7 mobius19   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 43
  • Joined: 26-November 08

Re: html code in php

Posted 06 April 2009 - 09:52 PM

View Postmobius19, on 6 Apr, 2009 - 05:20 PM, said:

I'm sorry for the trouble for all you guys that i may be causing.. It's just my form which is in php code is inside my html page is not sending the infos. on my email. I'm suspecting it's because the bind between html and php coding that i may be doing wrong. or another question,would a php code inside a div tag will work? eg.
<div id="container">
<? code code.. ?>
<form action="process.php" method="post"
tables etc...
</form>
</div>



Though on my page it is saying message was successfully sent but im not getting it on my mail.I also chmod my file to 777.oh men i'm lost..


i found answer to my question: Its the hostting account i used that is preventing it to process thew form. Thanks guys for the help. Have a good day to all!
Was This Post Helpful? 0
  • +
  • -

#8 chiliwillie11   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-April 09

Re: html code in php

Posted 07 April 2009 - 12:21 AM

I have come to use only single quotes when writing html. A browser will recognize <a href="www.mypage.com"> or <a href='www.mypage.com'> as the same thing. If you only use single quotes for your html code, you don't have this problem when you try to echo it in php.

Like sl4ck3r said, you could also escape the quotes with a backslash, but that can be kind of a pain if you have to do it a lot, plus it doesn't doesn't look as clean in my opinion.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1