PHP and MySQL Web Development - P29

PHP and MySQL Web Development - P29: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | Matching and Replacing Substrings with String Functions 107 Finding Strings in Strings strstr strchr strrchr stristr To find a string within another string you can use any of the functions strstr strchr strrchr or stristr . The function strstr is the most generic and can be used to find a string or character match within a longer string. Note that in PHP the strchr function is exactly the same as strstr although its name implies that it is used to find a character in a string similar to the C version of this function. In PHP either of these functions can be used to find a string inside a string including finding a string containing only a single character. The prototype for strstr is as follows string strstr string haystack string needle You pass the function a haystack to be searched and a needle to be found. If an exact match of the needle is found the function returns the haystack from the needle onward otherwise it returns false. If the needle occurs more than once the returned string will start from the first occurrence of needle. For example in the Smart Form application we can decide where to send the email as follows toaddress feedback@ the default value Change the toaddress if the criteria are met if strstr feedback shop toaddress retail@ else if strstr feedback delivery toaddress fulfilment@ else if strstr feedback bill toaddress accounts@ This code checks for certain keywords in the feedback and sends the mail to the appropriate person. If for example the customer feedback reads I still haven t received delivery of my last order the string delivery will be detected and the feedback will be sent to fulfilment@. There are two variants on strstr . The first variant is stristr which is nearly identical but is not case sensitive. This will be useful for this application as the customer might type delivery Delivery or DELIVERY . The second variant is strrchr which is again nearly identical but will return

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
9    88    2    20-04-2024
Đã 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.