LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   html into php (https://www.linuxquestions.org/questions/programming-9/html-into-php-357573/)

charnel 08-27-2005 02:36 PM

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

PenguinPwrdBox 08-27-2005 04:08 PM

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

tomj88 08-27-2005 04:08 PM

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 ' '.

tomj88 08-27-2005 04:09 PM

what are the chances of two people posting at exactly the same time?

spooon 08-27-2005 04:28 PM

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 ?>

charnel 08-28-2005 02:54 AM

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

eddiebaby1023 08-28-2005 02:18 PM

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.

caged 08-30-2005 10:47 AM

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.


All times are GMT -5. The time now is 08:41 PM.