Manual programming Experience Handbook part 60 potx

5 214 0
Manual programming Experience Handbook part 60 potx

Đang tải... (xem toàn văn)

Thông tin tài liệu

cách chính xác số lượng byte ghi vào file. Nếu ko có giá trị này, ta sẽ gặp những kết quả ko thể dự đoán trước. Vậy là sau bài này chúng ta đã biết thêm một chút về Một số thao tác khi làm việc với file trong PHP, bao gồm Mở, ĐÓng, Đọc và Ghi file. Bài tiếp theo sẽ đi vào nghiên cứu Permission của file cũng như một số vấn đề quan trọng khác. identical(UDS) Giới thiệu sơ lược về cookie Nguồn: ThegioiPHP.com Cookie thường được sử dụng để xác định thông tin của người sử dụng. Cookie là gì ? Cookie là một file nhỏ mà server nhúng vào trên máy người sử dụng. Mỗi lần có yêu cầu từ chính máy đó cho một trang với một trình duyệt, nó cũng sẽ gửi cookie. Với PHP, bạn có thể tạo và truy cập giá trị của cookie. Làm thế nào để tạo một cookie ? Hàm setcookie() được sử dụng để tạo cookie. Lưu ý: Hàm setcookie() phải có TRƯỚC thẻ <html>. Cú pháp: PHP Code: setcookie(name, value, expire, path, domain); Ví dụ Ví sụ sau sẽ đặt một cookie tên là uname - cookie này sẽ hết hạn trong 10 tiếng đồng hồ. PHP Code: <?php setcookie("uname", $name, time()+36000); ?> <html> <body> <p> A cookie was set on this page! The cookie will be active when the client has s ent the cookie back to the server. </p> </body> </html> Lấy thông tin từ cookie Khi cookie đã được đặt, PHP sử dụng tên của cookie như là một biến. Sử dụng hàm isset() để xem cookie có được đặt hay không. Ví dụ Ví dụ sau sẽ kiểm tra xem cookie uname đã được đặt rồi hay chưa và sau đó in ra thông báo. PHP Code: <html> <body> <?php if (isset($_COOKIE["uname"])) echo "Welcome " . $_COOKIE["uname"] . "!<br />"; else echo "You are not logged in!<br />"; ?> </body> </html> PHP Cheat Sheet Function List Probably the biggest problem with PHP is its inconsistency. Some function names use underscores, some don't. Some are of the form "verb object" and some are "object verb". Some use "2" instead of "to". The side sections of the cheat sheet list many of the most commonly used functions in PHP and are there to provide a quick reference to check function names. SuperGlobals In PHP, SuperGlobals are available at any point in a script, and allow access to data from the user and session date, as well as information about server settings and environmental data. This section contains a list of SuperGlobal variable names. Date Formatting There are, as I'm sure you are aware, a huge number of options when it comes to date formatting, and there are few people who remember all of them. This section of the cheat sheet lists the various options, followed by a description, and an example where appropriate. Regular Expression Syntax Many people have trouble with regular expressions, and the first step to coming to grips with them is to become familiar with the various symbols used in regular expressions and their meaning. This section lists these symbols and describes their meaning. PCRE Modifiers "PCRE" stands for "Perl Compatible Regular Expressions". In PHP, this refers to functions like "preg_replace" and "preg_split". The patterns used in these functions can have modifiers applied to them, and this section list those modifiers and what they do. Function Argument Orders One of the other major inconsistencies in PHP is function argument ordering. Functions that are very very similar often completely opposite ordering of arguments. This section simply lists a few of the common ones people are sometimes confused by, or that people find easy to forget. fopen() Modes fopen() is a widely used function and has several modes in which it can operate, depending on whether you want to read or write to a file, and what you want to do with data already in that file. This section lists those modes and what each does. One.N(UDS) Kiểu dữ liệu PHP (tiếp theo - bon tren) PHP hỗ trợ tám kiểu dữ liệu nguyên thuỷ. Bốn kiểu thông thường là: boolean, integer, floating-point number(float), string. Hai kiểu phức tạp là: mảng( array) và đối tượng ( object). Và cuối cùng là hai kiểu đặc biệt : resource và NULL. Loại dữ liệu của biến thông thường không được gán bởi người lập trình mà được quyết định tại thời gian chạy của PHP, phụ thuộc vào ngữ cảnh mà biến được dùng. 1. Boolean: đây là kiểu đơn giản nhất. Một kiểu boolean biểu thị một giá trị thật. Nó có thể là TRUE hay FALSE. Cú pháp: để chỉ định một giá trị boolean, có thể sử dụng từ khoá TRUE hay là FALSE. Cả hai đều không phân biệt chữ hoa hay chữ thường. Ví dụ: Code: $foo=True; // gán giá trị TRUE cho biến $foo. Để có thể chuyển một giá trị sang kiểu boolean, chúng ta có thể dùng (bool) hay (boolean). Tuy nhiên trong hầu hết các trường hợp bạn không cần phải sử dụng việc ép kiểu này, bởi giá trị sẽ được tự động chuyển nếu nó là một toán tử, hàm hay là cấu trúc điều khiển đòi hỏi một tham số kiểu boolean. Chú ý: -1 được xem là TRUE, giống như các giá trị khác 0 khác ( bất kể là số dương hay âm). . hạn trong 10 tiếng đồng hồ. PHP Code: <?php setcookie("uname", $name, time()+ 3600 0); ?> <html> <body> <p> A cookie was set on this page! The cookie

Ngày đăng: 06/07/2014, 01:20

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan