Jump to content

html code into php


kokeroulis

Recommended Posts

You probably didn't escape your quotes that you used to start a string.Error:echo 'O' Reilly';PHP will think I have ended the string after the letter O, and think Reilly constant (isn't defined), and I didn't concatenate (join the scalar (single value like strings and numbers) values together).So you will have to escape them by placing a \ before the character that needs to be escaped.echo 'O\' Reilly';

Link to comment
Share on other sites

Hi, i don't know how its this formally called, but you can code with php and html in the same file and still not being 'mixed', like this:<?php...//code...if(condition){?><form acti.....> <input .... value="<?php echo $myvar; ?>" /></form><?php}?>hope this helps

Link to comment
Share on other sites

Double quotes inside double quotes must be escaped. You could also change them to single quotes. Or you could "trap" your HTML inside a PHP condition that spans two PHP tags. This looks a little weird if you've never seen it, but it really works:

<?php	$m = 5;	if ($m == 5) { // OPENING THE BRACES HERE CAUSES THE HTML BELOW TO BE PRINTED ONLY IF THE CONDITION IS TRUE?><form method="post" action="test.php">	<input name="name" value="" type="text"><br>	<input type="submit"><br></form><?php	} // AND WE CLOSE THE BRACE HERE?>

This is especially useful (and easy to read) if the trapped HTML doesn't contain any PHP variables that need to be interpolated.

Link to comment
Share on other sites

Double quotes inside double quotes must be escaped. You could also change them to single quotes. Or you could "trap" your HTML inside a PHP condition that spans two PHP tags. This looks a little weird if you've never seen it, but it really works:
<?php	$m = 5;	if ($m == 5) { // OPENING THE BRACES HERE CAUSES THE HTML BELOW TO BE PRINTED ONLY IF THE CONDITION IS TRUE?><form method="post" action="test.php">	<input name="name" value="" type="text"><br>	<input type="submit"><br></form><?php	} // AND WE CLOSE THE BRACE HERE?>

This is especially useful (and easy to read) if the trapped HTML doesn't contain any PHP variables that need to be interpolated.

thanks.And something else if i want to use the var $_POST["name"] from the above form into the second PHP tag will it work?
Link to comment
Share on other sites

Yes. All variables you declare outside of functions are global throughout the document, as are superglobals like $_POST. That is, their scope is not limited to one set of <?php ?> tags. Different tags simply demarcate portions of the script from the true HTML portions. Think of it this way: there is only one script per document, though it may come in more than one section.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...