PHP Common gloomy problem answer _php skill

Source: Internet
Author: User
Tags explode
PHP Common depressed problem answer
Transfer from Joy Village
Register_global defaults to off in later versions of PHP4.2
to obtain a variable submitted from another page:
method One:Locate the Register_global in the php.ini and set it to on.
Method Two:This extract ($_post) is placed at the top of the receiving page, and extract ($_get) must have extract () before the $_session (Session_Start) is noted;(.
Method Three:One reading variable $a=$_get["a"]; $b =$_post["B"], this method is troublesome but relatively safe.
PHP Code:
? Php
Ob_start ();
Session_Start ();
Echo "<pre>";
Echo "The _get variables obtained on this page are:";
Print_r ($_get);
Echo "The _post variables obtained on this page are:";
Print_r ($_post);
Echo "The _cookie variables obtained on this page are:";
Print_r ($_cookie);
Echo "The _session variables obtained on this page are:";
Print_r ($_session);
Echo "</pre>";
?>
when I transfer a variable to another page, I get only the first half, and all that start with a space are lost .
PHP Code:--------------------------------------------------------------------------------
<?php
$Var = "Hello php";//Modify to $var= "Hello php"; try to get a result
$post = "receive.php?" Name= ". $Var;
Header ("Location: $post");
?>
--------------------------------------------------------------------------------
Content of receive.php:
PHP Code:--------------------------------------------------------------------------------
? Php
Echo "<pre>";
Echo $_get["Name"];
Echo "</pre>";
?>
--------------------------------------------------------------------------------
the correct approach is to:
PHP Code:--------------------------------------------------------------------------------
<?php
$Var = "Hello php";
$post = "receive.php?" Name= ". UrlEncode ($Var);
Header ("Location: $post");
?>
--------------------------------------------------------------------------------
On the receiving page you do not need to use UrlDecode (), the variable is automatically encoded.
specification of your SQL statements
In the table, precede the field with "'" so that no error occurs because of misuse of the keyword.
Of course I don't recommend using keywords.
For example
$SQL = "INSERT into ' xltxlm ' (' Author ', ' title ', ' id ', ' content ', ' Date ') VALUES (' xltxlm ', ' use ', 1, ' criterion your Sql s Tring ', ' 2003-07-11 00:00:00 ')
How do I know what functions the system supports by default?
PHP Code:
--------------------------------------------------------------------------------
<?php
$arr = Get_defined_functions ();
Function php () {
}
echo "<pre>";
Echo "Here shows all the functions supported by the system, and the custom function php\n";
Print_r ($arr);
echo "</pre>";
?>

How to compare two dates by a few days
PHP Code:
--------------------------------------------------------------------------------
? Php
$Date _1= "2003-7-15";//may also be: $Date _1= "2003-6-25 23:29:14";
$Date _2= "1982-10-1";
$Date _list_1=explode ("-", $Date _1);
$Date _list_2=explode ("-", $Date _2);
$d 1=mktime (0,0,0, $Date _list_1[1], $Date _list_1[2], $Date _list_1[0]);
$d 2=mktime (0,0,0, $Date _list_2[1], $Date _list_2[2], $Date _list_2[0]);
$Days =round (($d 1-$d 2)/3600/24);
Echo "I have struggled for $Days days ^_^";
?>
data put into the database and taken out to display on the page need to pay attention to what
When in storage
$str =addslashes ($STR);
$sql = "INSERT INTO ' tab ' (' Content ') VALUES (' $str ')";
When you are out of the library
$str =stripslashes ($STR);
When displayed
$str =htmlspecialchars (NL2BR ($STR));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.