LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-27-2005, 02:36 PM   #1
charnel
Member
 
Registered: Mar 2005
Distribution: mandrake 10.0
Posts: 58

Rep: Reputation: 15
html into php


how can I insert html tags into php codes I cannot remember the <?> can you please help me... And Can I use variables in html with that technique
 
Old 08-27-2005, 04:08 PM   #2
tomj88
Member
 
Registered: Apr 2005
Location: Wolverhampton, England
Distribution: Ubuntu
Posts: 334

Rep: Reputation: 30
Sorry, I'm not too sure about your problem. But you can do stuff like:
<html>
<head>
<title>Welcome to my site!</title>
</head>
<body>
<?php
echo 'Hello World!';
echo "</body>";
print "</html>";
?>

Hope this helps. Notice, echo and print (afaik) do exactly the same task. To print text or html tags, you must enclose the text imbetween " " or ' '.
 
Old 08-27-2005, 04:08 PM   #3
PenguinPwrdBox
Member
 
Registered: Oct 2003
Location: /illinois/chicago
Distribution: Slackware/Gentoo/FC/RHEL
Posts: 568

Rep: Reputation: 30
You would use php to "print" the tags you seek to create. There are a number of methods for doing this - the most common of which is surrounding logic and variables. You can assign a variable in php, and then use the logic to control what HTML is generated......
 
Old 08-27-2005, 04:09 PM   #4
tomj88
Member
 
Registered: Apr 2005
Location: Wolverhampton, England
Distribution: Ubuntu
Posts: 334

Rep: Reputation: 30
what are the chances of two people posting at exactly the same time?
 
Old 08-27-2005, 04:28 PM   #5
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 48
As for printing plain HTML in PHP, I want to note that one can simply exit PHP mode with "?>" and reenter PHP mode with "<?php" and it is equivalent to echoing everything within those tags. Even when you use this technique inside of a conditional (if, etc.) block or loop, the echoing only happens when the block is actually executed, just like you would expect from regular "echo" statements.

Quote:
Originally posted by charnel
And Can I use variables in html with that technique
You can always use
Code:
<?php echo $foo; ?>
or the short tag syntax (not always supported):
Code:
<?= $foo ?>
 
Old 08-28-2005, 02:54 AM   #6
charnel
Member
 
Registered: Mar 2005
Distribution: mandrake 10.0
Posts: 58

Original Poster
Rep: Reputation: 15
thank you all for your replies...But I think there aws an another way to insert html into php than echo all the lines... The thing that I am tring to do is to create a new html or php file with fopen command....
 
Old 08-28-2005, 02:18 PM   #7
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Quote:
Originally posted by charnel
thank you all for your replies...But I think there aws an another way to insert html into php than echo all the lines... The thing that I am tring to do is to create a new html or php file with fopen command....
If you find that other way, do tell us - I don't think it exists. PHP blocks are replaced by the browser with the output of the PHP block, so if you don't print or echo anything, you get an empty block. The way to insert HTML into a PHP file without echo90ing it is to enclose it between ?> and <?php tags.
 
Old 08-30-2005, 10:47 AM   #8
caged
Member
 
Registered: Jan 2004
Location: new zealand
Distribution: Mandrake,Slackware
Posts: 165

Rep: Reputation: 30
Code:
<?
 print("<html>
    <head></head>
    <body>body text</body>
    </html>
 ");

?>
or
Code:
<html>
<?
 print("<head></head>
     <body>
     body text
 ");
?>
</body>
</html>
fopen opens a given file so that the data in the file can be accessed by the PHP program its not likely you would use it to include html code.

there is the include command though...
Code:
<?
  include("somehtmlfile.html");
?>
...That would allow you to include the contents of the html document 'somehtmlfile.html' at that point in your PHP document.

hope thats helpful.

Cheers,
Ben.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP/html forum FedoraUsr Programming 2 08-18-2005 01:07 PM
HTML fighting PHP aciesd Linux - Software 3 07-16-2005 08:05 AM
html to php? help me please!!!!! trscookie Programming 4 01-24-2005 06:36 AM
HTML Tidy and PHP 4 atom Programming 0 10-01-2004 10:06 AM
php/html editor dai Linux - Software 10 03-10-2003 04:34 PM


All times are GMT -5. The time now is 05:29 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration