TAILIEUCHUNG - PHP 5 Recipes A Problem-Solution Approach 2005 phần 5

Tuy nhiên, mô hình hướng đối tượng tồn dư từ PHP 3, thì hầu không được chú ý đến. Mặc dù mô hình đối tượng này cực kì hạn chế song chúng vẫn được sử dụng hết sức rộng rãi trên thế giới thậm chí là ngay cả trong các ứng dụng PHP rất lớn. Nhu cầu sử dụng rất cao đối với mô hình lập trình kém của nó đã khiến cho các nhà kiến tạo ngôn ngữ quyết định chọn nó làm mục tiêu chính để nâng cấp PHP 4 lên PHP 5 | 270 6-4 USING SUBSTRING ALTERNATIVES height of the block where the text is supposed to be output is big enough to handle only 300 characters of text. If the amount of text outputted exceeds that the site could potentially break causing the entire design to look flawed this is not good considering this is an important client. In addition consider that the client is not sure at all how many characters to use and even if you had informed them to use only 300 there is still a real chance they would try their luck anyway. How then can you guarantee that the design will not break Well this sounds like a lovely test for our good friend Mr. substr and his buddy Ms. strlen . The Code php theclientstext Hello how are you today I am fine if strlen theclientstext 30 echo substr theclientstext 0 29 else echo theclientstext Hello how are you today I a How It Works The first thing this block of code does is check to make sure the text provided by the client is within the length you need it to be if strlen theclientstext 30 If it happens to fall outside the range of acceptable length you then use the lovely substr function to echo only the portion of the text that is deemed acceptable. If the client has entered a proper block of text then the system merely outputs the text that was entered and no one is the wiser. By using the function substr you have averted a potential disaster. People browsing the site will see nothing but a slightly concatenated set of verbiage so the site s integrity remains sound. This sort of rock-solid validation and programming can save business relationships as clients are seldom fond of having their site appear broken to potential customers or intrigued individuals. 6-4. Using Substring Alternatives You can consider the substr function as something of a jack of all trades. It can get you whatever you are looking for in a string with the greatest of ease. Sometimes however it may not be necessary to go to the trouble of using such a versatile function. .

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.