PHP 5/MySQL Programming- P37

PHP 5/MySQL Programming- P37:computer programming has often been seen as a difficult and arcane skill. Programming languages are difficult and complicated, out of the typical person’s reach. However, the advent of the World Wide Web has changed that to some extent. It’s reasonably easy to build and post a Web page for the entire world to see. The language of the Web is reasonably simple, and numerous applications are available to assist in the preparation of static pages | 158 PHP 5 MySQL Programming for the Absolute Beginner Finding a Substring with substr The algorithm s behavior depends on the first character of each word. I need to know all the rest of the word without the first character. The substr function is useful for getting part of a string. It requires three parameters. The string you want to get a piece from Which character you want to begin with starting with 0 as usual How many characters you want to extract I got the first letter of the word with this line firstLetter substr theWord 0 1 It gets one letter from theWord starting at the beginning of the word position 0 . I stored that value in the firstLetter variable. It s not much more complicated to get the rest of the word restOfWord substr theWord 1 strlen theWord -1 Once again I need to extract values from theWord. This time I begin at character 1 which humans would refer to as the second character . I don t know directly how many characters to get but I can calculate it. I should grab one less character than the total number of characters in the word. The strlen function is perfect for this operation because it returns the number of characters in any string. I can calculate the number of letters I need with strlen theWord - 1. This new decapitated word is stored in the restOfWord variable. Using strstr to Search for One String Inside Another The next task is to determine if the first character of the word is a vowel. You can take a number of approaches to this problem but perhaps the easiest is a searching function. I created a string with all the vowels aeiouAEIOU and then I searched for the existence of the firstLetter variable in the vowel string. The strstr function is perfect for this task. It takes two parameters the string you are looking for given the adorable name haystack in the online documentation and the string you are searching in the needle . To search for the value of the firstLetter variable in the string constant aeiouAEIOU I used the following .

Không thể tạo bản xem trước, hãy bấm tải xuống
Đã 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.