Jump to content

Php Queries


gameboyz

Recommended Posts

echo "Hello" (without quotes) is interpreted quicker. The contents of double quoted strings are interpreted, while strings with single quotes are printed verbatim. For example:

$var = "Hello";echo "I say $var"; //echos "I say Hello"echo 'I say $var'; //echos "I say $var"

Single quotes are interpreted quicker, but double quotes are quicker than concatenation.

Link to comment
Share on other sites

Double quotes go through the process of converting variables/special characters into their values, where if you were to use single quotes, it wouldn't convert them and just print the string as is.

<?php  $var='4';  echo "$var"?>This would output 4

<?php  $var='4';  echo '$var';?>This would output $var

Link to comment
Share on other sites

echo "Hello" (without quotes) is interpreted quicker. The contents of double quoted strings are interpreted, while strings with single quotes are printed verbatim. For example:
$var = "Hello";echo "I say $var"; //echos "I say Hello"echo 'I say $var'; //echos "I say $var"

Single quotes are interpreted quicker, but double quotes are quicker than concatenation.

What'd you mean double quotes are quicker than concatenation?2) About form enctype (http://www.w3schools.com/tags/att_form_enctype.asp) what's the difference between the 3? I experimented with try it editor using the first two, each time using "#$%^&" as first and last name and the results are identical.
Link to comment
Share on other sites

2) About form enctype (http://www.w3schools.com/tags/att_form_enctype.asp) what's the difference between the 3? I experimented with try it editor using the first two, each time using "#$%^&" as first and last name and the results are identical. Edit: This is weird. I tried it out not using the try it editor with the script as followed:

<?phpif (!isset($_REQUEST['submit'])) {?><html><head><title>PHP Labs</title></head><body><form action="<?php echo $_SERVER['PHP_SELF'];?>" method="get" enctype="application/x-www-form-urlencoded">  First name: <input type="text" name="fname" /><br />  Last name: <input type="text" name="lname" /><br />  <input type="submit" value="Submit" name="submit" /></form></body></html><?php}else {$fname=$_REQUEST["fname"];$lname=$_REQUEST["lname"];?><html><head><title>PHP Labs</title></head><body><textarea><?php echo "$fname $lname"; ?></textarea></body></html><?php}?>

No matter what I use for enctype it is the same. However it differs from try it editor in the sense that spaces are still spaces and they won't be converted to "+".

Link to comment
Share on other sites

  • 1 month later...

Anything wrong?

<?phpfunction writecookie($name,$value,$expire) {$expire=time()+$expire;setcookie($name,$value,$expire);}?><html><head><title>PHP Test Labs</title></head><body><?phpwritecookie('cookie','value',120);echo $_COOKIE['cookie'];?></body></html>

Link to comment
Share on other sites

I posted here: http://w3schools.invisionzone.com/index.php?showtopic=24775 and someone agreed that PHP cookies are easier to handle than JS ones.However since cookies gotta be set before any output, is it wise to use Javascript to set cookies and PHP to read the cookies? Since JS cookies can be set by a trigger (eg onclick) and PHP cookie-reading can be done after starting the HTML output.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...