Jump to content

Php Queries


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 post
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 post
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 post
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 post
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 post
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 post
Share on other sites

It's better to use PHP for everything, the user can disable Javascript. Sending headers before you output anything shouldn't be a problem if you structure your PHP code correctly.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...