TAILIEUCHUNG - Phát triển web với PHP và MySQL - p 14

String Manipulation and Regular Expressions CHAPTER 4 105 return a number greater than zero. If str1 is less than str2, strcmp() will return a number less than zero. This function is case sensitive. The function strcasecmp() is identical except that it is not case sensitive. The function strnatcmp() and its non-case sensitive twin, strnatcasecmp(), were added in PHP 4. These functions compare strings according to a “natural ordering,” which is more the way a human would do it. For example, strcmp() would order the string “2” as greater than the string “12” because it is lexicographically greater. strnatcmp() would do it the. | String Manipulation and Regular Expressions 105 Chapter 4 return a number greater than zero. If strl is less than str2 strcmp will return a number less than zero. This function is case sensitive. The function strcasecmp is identical except that it is not case sensitive. The function strnatcmp and its non-case sensitive twin strnatcasecmp were added in PHP 4. These functions compare strings according to a natural ordering which is more the way a human would do it. For example strcmp would order the string 2 as greater than the string 12 because it is lexicographically greater. strnatcmp would do it the other way around. You can read more about natural ordering at http projects natsort Testing String Length with strlen We can check the length of a string with the strlen function. If you pass it a string this function return its length. For example strlen hello returns 5. This can be used for validating input data. Consider the email address on our form stored in email. One basic way of validating an email address stored in email is to check its length. By my reasoning the minimum length of an email address is six characters for example a@ if you have a country code with no second level domains a one-letter server name and a one-letter email address. Therefore an error could be produced if the address was not this length if strlen email 6 echo That email address is not valid exit finish execution of PHP script Clearly this is a very simplistic way of validating this information. We will look at better ways in the next section. Matching and Replacing Substrings with String Functions It s common to want to check if a particular substring is present in a larger string. This partial matching is usually more useful than testing for equality. In our Smart Form example we want to look for certain key phrases in the customer feedback and send the mail to the appropriate department. If we want to send emails talking about Bob s shops to the retail .

TỪ KHÓA LIÊN QUAN
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.