TAILIEUCHUNG - PHP and MySQL Web Development - P28

PHP and MySQL Web Development - P28: 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. | 102 Chapter 4 String Manipulation and Regular Expressions characters as control problematic ones are quotes single and double backslashes and the NUL character. We need to find a way of marking or escaping these characters so that databases such as MySQL can understand that we meant a literal special character rather than a control escape these characters add a backslash in front of them. For example double quote becomes backslash double quote and backslash becomes backslash backslash . This rule applies universally to special characters so if you have in your string you need to replace it with . PHP provides two functions specifically designed for escaping characters. Before you write any strings into a database you should reformat them with AddSlashes for example feedback AddSlashes feedback Like many of the other string functions AddSlashes takes a string as parameter and returns the reformatted string. When you use AddSlashes the string will be stored in the database with the slashes in it. When you retrieve the string you will need to remember to take the slashes out. You can do this using the StripSlashes function feedback StripSlashes feedback Figure shows the actual effects of using these functions on the string. Figure After calling the AddSlashesQ function all the quotes have been slashed out. StripSlashesQ removes the slashes. You can also set PHP up to add and strip slashes automatically. This is called using magic can read more about magic quotes in Chapter 21 Other Useful Features. Joining and Splitting Strings with String Functions 103 Joining and Splitting Strings with String Functions Often we want to look at parts of a string individually. For example we might want to look at words in a sentence say for spellchecking or split a domain name or email address into its component parts. PHP provides several string functions and one regular expression function that allow us to do this. In our example Bob .

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