Must be an associative array of associative arrays in the format Defaults to params Must be an associative array in the format file_get_contents() is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance.
Parametersfilename Name of the file to read. $filename 0
$filename 4A valid context resource created with stream_context_create(). If you don't need to use a custom context, you can skip this parameter by $filename 6The offset where the reading starts on the original stream. Negative offsets count from the end of the stream. Seeking ( $filename 8Maximum length of data read. The default is to read until end of file is reached. Note that this parameter is applied to the stream processed by the filters. Return ValuesThe function returns the read data or Warning This function may return Boolean Errors/ExceptionsAn When file_get_contents() is called on a directory, an ChangelogVersionDescription8.0.0$filename 8 is nullable now.7.1.0Support for negative $filename 6s has been added.ExamplesExample #1 Get and output the source of the homepage of a website
Example #2 Searching within the include_path
Example #3 Reading a section of a file
The above example will output something similar to: string(14) "lle Bjori Ro" Example #4 Using stream contexts
Notes
Tip A URL can be used as a filename with this function if the have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. Warning When using SSL, Microsoft IIS will violate the protocol by closing the connection without sending a Form là 1 đối tượng (hoặc cụ thể hơn là thẻ Thẻ
Cú pháp: <form name="..." action="..." method="..."> Các thành phần của form </form> Các thuộc tính của form:
Tìm hiểu POST và GET trong PHPPOST, GET là phương thức truyền dữ liệu trong form từ trang này qua trang khác và khối lượng dữ liệu truyền đi của form bị giới hạn bởi chiều dài tối đa của một URL (chiều dài tối đa của một URL là 2048 bytes và giới hạn này cũng phụ thuộc vào trình duyệt web). Để truyền được dữ liệu trong form từ trang này sang trang khác có những yêu cầu sau:
Để demo trong quá trình trình bày tạo 2 file <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html>2 là <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html>3 và <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html>4 trong thư mục <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html>5.
<html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html>3 sẽ có một form chứa các trường dữ liệu là <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html>7 và <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html>8 do người dùng nhập vào. File <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html>4 sẽ lấy các thông tin từ form bên trang <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html>3 truyền sang và hiển thị lên trình duyệt khi nhất button submit. Để nhận dữ liệu từ form truyền qua sử dụng biến toàn cục trong PHP.
Giống nhauPhương thức POST và GET đều là cơ chế truyền dữ liệu trong form từ trang này sang khác. Khác nhauPhương thức POSTCác dữ liệu của form được truyền ngầm và dữ liệu truyền đi không phụ thuộc vào URL. Ưu điểm
Nhược điểmDữ liệu truyền đi không tường mình (cơ chế truyền ngầm định) do đó sẽ phát sinh lỗi tiềm ẩn. DemoFile <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html>3 sử dụng phương thức POST: <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html> Kết quả khi chạy trên trình duyệt file <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html>3 File <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html>4 sử dụng biến toàn cục <html> <head> </head> <body> <?php $username = $_POST['txtUserName']; $password = $_POST['txtPassword']; echo "<p>UserName : ".$username."</p>"; echo "<p>Password : ".$password."</p>"; ?> </body> </html>7 để lấy dữ liệu từ form truyền sang. <html> <head> </head> <body> <?php $username = $_POST['txtUserName']; $password = $_POST['txtPassword']; echo "<p>UserName : ".$username."</p>"; echo "<p>Password : ".$password."</p>"; ?> </body> </html> Nhập <html> <head> </head> <body> <?php $username = $_POST['txtUserName']; $password = $_POST['txtPassword']; echo "<p>UserName : ".$username."</p>"; echo "<p>Password : ".$password."</p>"; ?> </body> </html>8 và <html> <head> </head> <body> <?php $username = $_POST['txtUserName']; $password = $_POST['txtPassword']; echo "<p>UserName : ".$username."</p>"; echo "<p>Password : ".$password."</p>"; ?> </body> </html>9. Nhấn Phương thức GETCác dữ liệu đường truyền đi được hiển thị lên URL của trình duyệt và dữ liệu truyền đi phụ thuộc vào độ dài đối đa của URL. Ưu điểm
Nhược điểm
DemoFile a sử dụng phương thức GET <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="get"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/> <br/> </form> </body> </html> File <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html>4 sử dụng biến toàn cục <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="get"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/> <br/> </form> </body> </html>2 để lấy dữ liệu từ form truyền sang. <html> <head> </head> <body> <?php $username = $_GET['txtUserName']; $password = $_GET['txtPassword']; echo "<p>UserName : ".$username."</p>"; echo "<p>Password : ".$password."</p>"; ?> </body> </html> Chạy file <html> <head></head> <title>Demo Post and Get</title> <body> <form name="frmLogin" action="b.php" method="post"> <label>User Name: </label> <input type="text" name="txtUserName"/><br/> <label>Password: </label> <input type="password" name="txtPassword" /><br/> <input type="submit" value="Log in"/><br/> </form> </body> </html>3 sau đó nhập nội dung như trường hợp sử dụng phương thức POST sẽ thấy kết quả là các dữ liệu được truyền đi được hiển thị lên URL của trình duyệt. Lưu ý là dữ liệu truyền đi là có giới hạn phụ thuộc vào độ dài của URL (tối đa 2048 bytes). |