1: Why can't I get a variable I have to go to another web POST data name, why do you get any value when you output $ NAME? Register_global defaults in the version after PHP4.2 is OFF If you want to get from another Page Submit Variable: Method 1: Find register_global in php.ini and set it to ON. Method 2: Put this extract ($ _ post) on receiving the page; ($ _ get); (note extract) Before $ _SESSION) must have session_start ()). Method 3: A read variable $ A = $ _ get ["a"]; $ b = $ _ post ["b"], etc., this method is trouble, but Compare safety .2: Debugging your program must know what a variable is in runtime. I did this, build a file debug.php, the content is as follows:
PHP code:
PHP
Ob_start ();
Session_start ();
Echo "
";Echo "This page is _GET variables are:";
Print_r ($ _ get);
Echo "The _post variables obtained on this page are:";
Print_r ($ _ post);
Echo "The _cookie variable from this page is:";
Print_r ($ _ cookie);
Echo "The _ssion variables obtained on this page are:";
Print_r ($ _ session);
ECHO " pre>";
?>
Then set in php.ini: include_path = "c: / php", and put the debug.php in this folder, you can include this file in each web page, view the obtained variable name and value .3: How to Using sessions All with session, you must call the function session_start (); it is simple to pay for the session, such as:
PHP code:
PHP
Session_start ();
$ Name = "This is a session example";
Session_register ("name"); // Notice, don't write: session_register ("$ name");
Echo $ _SESSION ["Name"];
// $ _SESSION ["name"] "This is a session example"
?>
After PHP4.2, you can pay for the session:
PHP code:
PHP
Session_start ();
$ _SESSION ["Name"] = "Value";
?>
Cancel session can be like this:
PHP code:
PHP
session_start ();
session_unset ();
session_destroy ();
?>
Cancel a session variable is also bug above PHP4.2. Note: 1: No output before calling session_start (). For example, it is wrong. =============== =========================== 1 line 2 line Php3 line session_start (); // There is already output in the first line 4 Row ..... 5 line?> =========================================== == Tip 1: Any "....... HEADERS ALREADY SENT ..........", it is sent to the browser before session_start (). It is normal to remove the output, (cookie also This error occurs, the error reason is the same) Tip 2: If your session_start () is placed in the loop statement, and it is difficult to determine where to output information to the browser, you can use the following method: 1 line Php ob_start ();?> ...... Here is your procedure ... 2: What is wrong with this? Warning: session_start (): Open (/ tmp / sess_7d190aa36b4c5ec13a5c1649cc2da23f, o_rdwr) failed: ... Because you don't specify the storage path of the session file. Solution: (1) Open php.ini in the C disk, find session.save_path, modified to session.save_path = "C: / TMP" 4 : Why do I send variables to another web page, I only get the first half, and all lost PHP code at the beginning of the space:
PHP
$ VAR = "Hello PHP"; // Modified to $ VAR = "Hello PHP"; try what results
$ pos = "Receive.php? Name =". $ VAR;
HEADER ("Location: $ POST");
?>
Receive.php content:
PHP code:
PHP
Echo "
";Echo $ _Get ["name"];
ECHO " pre>";
?>
The correct way is:
PHP code:
PHP
$ VAR = "Hello PHP";
$ pos = "Receive.php? Name =". Urlencode ($ VAR);
HEADER ("Location: $ POST");
?>
You don't need to use urldecode () in the receiving page, and the variable will automatically encode .5: How to intercept the designated length of Chinese characters without the end of "?>", Exceeding the part to "..." instead of general, to take it The variable comes from mysql, first to ensure that the length is long enough, generally CHAR (200), can keep 100 Chinese characters, including punctuation.
PHP code:
PHP
$ Str = "This character is long, ^ _ ^";
$ Short_STR = Showsh ($ STR, 4); // Intercept 4 Chinese characters, the result is: this character ... Echo "$ Short_STR";
Function Csubstr ($ STR, $ START, $ LEN)
{
$ Strlen = Strlen ($ STR);
$ clen = 0;
For ($ I = 0; $ I <$ Strlen; $ i , $ Clen )
{
IF ($ clen> = $ start $ g)
Break;
IF (Substr ($ Str, $ I, 1)> 0xA0)
{
IF ($ clen> = $ s)
$ Tmpstr. = Substr ($ STR, $ I, 2);
$ i ;
}
Else
{
IF ($ clen> = $ s)
$ Tmpstr. = SUBSTR ($ STR, $ I, 1);
}
}
Return $ TMPSTR;
}
Function Showsh ($ STR, $ LEN)
{
$ TEMPSTR = CSUBSTR ($ STR, 0, $ LEN);
IF ($ STR <> $ TEMPSTR)
$ Tempstr. = "..."; // What is the end of the end, modify it here.
Return $ TEMPSTR;
}
6: Specifies your SQL statement in front of the table, the field plus "` ", this will not have an error because of misuse the keyword, of course, I don't recommend you to use keywords. For example, $ sql =" Insert Into `XLTXLM `(` Author`, `Date`,`, `, ', 1,' criterion your sql string ',' 2003-07-11 00: 00:00 ') "" `" How to enter? On the Tab key. 7: How to make the string of the HTML / PHP format is not interpreted, but is displayed as
PHP code:
PHP
$ STR = "
php h1>";
Echo "is explained:" $ STR. "
processed:";Echo Htmlentities (NL2BR ($ Str));
?>
8: How to get the variable value outside the function in the function
PHP code:
PHP
$ a = "php";
Foo ();
Function foo ()
{
Global $ a; // Delete here to see what results
Echo "$ a";
}
?>
9: How do I know what function is supported by default?
PHP code:
PHP
$ arr = get_defined_functions ();
Function PHP () {
}
Echo "
";Echo "Here you display all functions supported by the system, and custom function PHP / N";
Print_r ($ ARR);
ECHO " pre>";
?>
10: How to compare two dates a few days
PHP code:
PHP
$ DATE_1 = "2003-7-15"; // can 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);
$ D1 = MKTIME (0, 0, 0. $ DATE_LIST_1 [1], $ DATE_LIST_1 [2], $ DATE_LIST_1 [0]);
$ D2 = MKTIME (0, 0, 0, $ DATE_LIST_2 [1], $ DATE_LIST_2 [2], $ DATE_LIST_2 [0]);
$ Days = ROUND (($ D1- $ D2) / 3600/24);
Echo "I have already struggled $ days day ^ _ ^";
?>
11: Why did I upgrade PHP, the original program appears full screen NOTICE: Undefined Variable: This is the meaning of the warning, because the variable is not defined. Open php.ini, find the bottom Error_Reporting, modify to Error_Reporting = E_ALL & ~ E_NOTICE For PARSE ERROR Error Error_Reporting (0) Can't close. If you want to close any error prompts, open php.ini, find DISPLAY_ERRORS, set to display_errors = off. After any errors will not be prompted. So what is error_reporting? 12: I want to add a file in front of each file. But one adds a very trouble 1: Open the php.ini file settings include_path = "c:" 2: Write two file auto_prepend_file.php and auto_append_file.php Save At the C drive, they will automatically attach to the head and tail of each PHP file.
3: Look in your php.ini: Automatically add files before or after any PHP document.auto_prepend_file = auto_prepend_file.php; attached to the head auto_append_file = auto_append_file.php; you rely on each php file is equivalent to the tail after
PHP code:
PHP
Include "auto_prepend_file.php";
....... / / Here is your program
INCLUDE "auto_append_file.php";
?>
13: How to use the PHP upload file
PHP code:
Upload File Form Title> Head>