TAILIEUCHUNG - Học php, mysql và javascript - p 12

Figure 5-1. The output of PHP’s built-in phpinfo function As you can see, the strrev function reversed the order of characters in the string, str_repeat repeated the string “Hip ” twice (as required by a second argument), and strtoupper converted “hooray!” to uppercase. Defining a Function The general syntax for a function is: function function_name([parameter [, .]]) { // Statements } I’ll explain all the square brackets, in case you find them confusing. The first line of the syntax indicates that: • A definition starts with the word function. • A name follows, which must start with a letter or underscore, followed by any number. | Figure 5-1. The output of PHP s built-in phpinfo function As you can see the strrev function reversed the order of characters in the string str_repeat repeated the string Hip twice as required by a second argument and strtoupper converted hooray to uppercase. Defining a Function The general syntax for a function is function function_name parameter . Statements I ll explain all the square brackets in case you find them confusing. The first line of the syntax indicates that A definition starts with the word function. A name follows which must start with a letter or underscore followed by any number of letters numbers or underscores. The parentheses are required. One or more parameters separated by commas are optional. PHP Functions 91 Function names are case-insensitive so all of the following strings can refer to the print function PRINT Print and PrInT. The opening curly brace starts the statements that will execute when you call the function a matching curly brace must close it. These statements may include one or more return statements which force the function to cease execution and return to the calling code. If a value is attached to the return statement the calling code can retrieve it as we ll see next. Returning a Value Let s take a look at a simple function to convert a person s full name to lowercase and then capitalize the first letter of each name. We ve already seen an example of PHP s built-in strtoupper function in Example 5-1. For our current function we ll use its counterpart strtolower lowered strtolower aNY of Letters and Punctuation you WANT echo lowered The output of this experiment is any of letters and punctuation you want We don t want names all lowercase though we want the first letter of each name capitalized. We re not going to deal with subtle cases such as Mary-Ann or Jo-En-Lai for this example. Luckily PHP also provides a ucfirst function that sets the first character of a string to uppercase ucfixed ucfirst any of letters and .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.