PDA

View Full Version : Simple php programming question


cashpath
03-08-2007, 06:53 PM
as a PHP newb I have a simple php question.

When you are inserting html code into your PHP document what is the best way to do it?

SHould you

1) leave php whenever you can? Like >? HTML CODE <?

2) or should you echo or ptint your html like

print " HTML code with a value=\"value\"";

The main reason I am asking is because you are supposed to put quotes around all values in html. SO I guess the real question is what is the best way to hanlde the quotes around the values?

Is it to escape the php? Or to backslash the quote tags EVERY TIME or is there an easier solution?


************************************************** ************************
UPDATE: I think I have found the answer for this. use single quotes on print statements... if this is not the best way let me know.

Thanks

harmor19
03-08-2007, 11:25 PM
I use
echo "HTML code with a value='value' ";
It's too much trouble adding slashes.

MarkPW
03-09-2007, 01:09 AM
When I want to output a large amount of html, then I tend to close and re-open the php tag. For small amounts, I use single quoted statements - but it's whatever suits you.

JorgeX
03-12-2007, 12:04 AM
Yeah, you can do a largest code and put a <?php $something ?>

Like:

<table width="750" height="24" border="0" align="center">
<tr>
<td><div align="center">
<?php
$thumbnaillimit=10; //How many thumbnails would you like to be displayed?
include("includes/thumbnails.inc.php");
?>
</div></td>
</tr>
</table> </td>
</tr>

or with echo:



<html>
<head>
<title>Problema</title>
</head>
<body>

<?php
echo "Nombre: <strong>".$_REQUEST['nombre']."</strong>";
echo "<br>";
switch ($_REQUEST['estudio']) {
case 'Primario':
echo "Nivel de Estudio Primario";
break;
case 'Secundario':
echo "Nivel de Estudio Secundario";
break;
case 'Terciario':
echo "Nivel de Estudio Terciario";
break;
default:
print "No ingres? Nivel de EstudiO";
}
?>

</body>
</html>


Else, you can include a PHP in html like this example:


<tr>
<td valign="top" class="totop">&nbsp;<span class="totop"><?php echo($comment); ?></span></td>
</tr>



Other way, you cant use INCLUDE TAG:


<?php include("ad.php"); ?>
</ br>
<p>
<?php include("ad2.php"); ?>
</p>
</DIV>

I hope it helps you