Hướng dẫn dùng worldhelloworld. trong PHP

Thông tin tài liệu

Ngày đăng: 19/11/2014, 17:33

Danh sách 98 hàm php dùng trong xử lí chuỗi, có hướng dẫn cách sử dụng, cấu trúc hàm, ví dụ dễ hiểu kèm theo có kết quả ví dụ giúp bạn dễ tiếp thu môn lập trình php. Bạn có thể xem thêm các ví dụ trên trang chủ của php http:php.net PHP – 98 HÀM XỬ LÍ CHUỖI 1. addcslashes($str, $char_list) — Hàm này sẽ thêm dấu gạch chéo (\) đằng trước những ký tự trong chuỗi $str mà ta liệt kê ở $char_list. z và A => Z // Kết quả: \P\H\P\n\e\t ?> 2. addslashes($str) — Thêm dấu gách chéo trước những ký tự (‘, “, \) trong chuỗi $str. 3. bin2hex($str) — Chuyển đổi dữ liệu dạng nhị phân sang dạng biểu diễn hệ hexa. 4. chop($str) — Loại bỏ những khoảng trắng ở cuối chuỗi. 5. chr($acii)— Cho một kí tự đặc biệt trong bảng mã ASCII 6. chunk_split($str, $len, $end) — Tách xâu $str thành các xâu nhỏ hơn với độ dài mỗi xâu là $len và kết thúc bằng xâu $end 7. convert_cyr_string — Chuyển đổi từ một kí tự Cyrillic sang một kí tự khác "; echo convert_cyr_string($str,'w','a'); //Chuyển kí tự "w" (windows-1251) thành "a" (x-cp866) // Kết quả: //Hello world! æøå //Hello world! ¦è¥ ?> 8. convert_uudecode — Decode a uuencoded string by Grimes 1 9. convert_uuencode — Uuencode a string 10. count_chars — Cho thông tin về các kí tự dùng trong xâu 11. crc32 — Tính toán sự thừa vòng đa thức của một xâu 12. crypt — :Một cách mã hóa một xâu "; } else { echo "Standard DES not supported.\n
"; } // 4 character salt if (CRYPT_EXT_DES == 1) { echo "Extended DES: ".crypt('something','_S4 some')."\n
"; } else { echo "Extended DES not supported.\n
"; } // 12 character salt starting with $1$ if (CRYPT_MD5 == 1) { echo "MD5: ".crypt('something','$1$somethin$')."\n
"; } else { echo "MD5 not supported.\n
"; } // Salt starting with $2a$. The two digit cost parameter: 09. 22 characters if (CRYPT_BLOWFISH == 1) { echo "Blowfish: ".crypt('something','$2a$09$anexamplestringforsalt$')."\n
"; } else { echo "Blowfish DES not supported.\n
"; by Grimes 2 } // 16 character salt starting with $5$. The default number of rounds is 5000. if (CRYPT_SHA256 == 1) { echo "SHA-256: ".crypt('something','$5$rounds=5000$anexamplestringforsalt$')."\n
"; } else { echo "SHA-256 not supported.\n
"; } // 16 character salt starting with $5$. The default number of rounds is 5000. if (CRYPT_SHA512 == 1) { echo "SHA-512: ".crypt('something','$6$rounds=5000$anexamplestringforsalt$'); } else { echo "SHA-512 not supported."; } ?> Kết quả: Standard DES: stqAdD7zlbByI Extended DES: _S4 someQXidlBpTUu6 MD5: $1$somethin$4NZKrUlY6r7K7.rdEOZ0w. Blowfish: $2a$09$anexamplestringforsaleLouKejcjRlExmf1671qw3Khl49R3dfu SHA-256: $5$rounds=5000$anexamplestringf$KIrctqsxo2wrPg5Ag/hs4jTi4PmoNKQUGWFXlVy9vu9 SHA-512: $6$rounds=5000$anexamplestringf$Oo0skOAdUFXkQxJpwzO05wgRHG0dhuaPBaOU/ oNbGpCEKlf/7oVM5wn6AN0w2vwUgA0O24oLzGQpp1XKI6LLQ0. 13. echo($str) — : In ra một hay nhiều xâu 14. explode($separator, $str, $limit) — Tách chuỗi $str thành mảng bởi chuỗi $separator Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day. ) ?> 15. fprintf — Viết một định dạng chuỗi ra một dòng 16. get_html_translation_table — xem danh sách các giá trị HTML entities " [&] => & [<] => < [>] => > ) ?> by Grimes 3 17. hebrev — Chuyển đổi văn ban logic khó hiểu sang văn ban trưc quan 18. hebrevc — Chuyển đổi văn ban logic khó hiểu sang văn ban trưc quan với sự chuyển đổi dòng mới 19. hex2bin — Decodes a hexadecimally encoded binary string 20. html_entity_decode — chuyển đổi các giá trị HTML entities được gọi bởi hàm htmlentities($str) về giá trị ban đầu Kết quả: < W3S h >� � ���� 21. htmlentities — chuyển đổi các ký tự sang giá trị HTML entities "� � ���� ; echo htmlentities($str); ?> Kết quả: <© W3Sçh°°¦§> 22. htmlspecialchars_decode — chuyển đổi các giá trị HTML entities được gọi bởi hàm htmlspecialchars () về giá trị ban đầu Kết quả: by Grimes 4 This is some bold text. 23. htmlspecialchars — chuyển đổi các ký tự được quy định trước sang giá trị HTML entities bold text."; echo htmlspecialchars($str); ?> Kết quả: This is some bold text. 24. implode($separator, $array) — Nối các phần tử mảng $array để tạo thành chuỗi, kí tự ngăn cách là $separator. 25. join($separator, $array) — Tương tự implode 26. lcfirst($str) — Make a string's first character lowercase 27. levenshtein — Tính khoảng cách giữa hai xâu "; echo levenshtein("Hello World","ello World",10,20,30);//30 ?> 28. localeconv — Lấy ra thông tin quy cách số . [thousands_sep] => , [int_curr_symbol] => USD [currency_symbol] => $ [mon_decimal_point] => . [mon_thousands_sep] => , [positive_sign] => [negative_sign] => - [int_frac_digits] => 2 [frac_digits] => 2 [p_cs_precedes] => 1 [p_sep_by_space] => 0 [n_cs_precedes] => 1 [n_sep_by_space] => 0 [p_sign_posn] => 3 [n_sign_posn] => 0 [grouping] => Array ( [0] => 3 ) [mon_grouping] => Array ( [0] => 3 ) ) ?> 29. ltrim — Loại bỏ các ký tự ở đầu chuỗi, mặc định loại bỏ tất cả khoảng trắng ở đầu chuỗi. "; echo ltrim($str,"Hello"); //Hello World! //World! ?> 30. md5_file — Mã hóa file dạng md5 31. md5 — Mã hóa chuỗi dạng md5 32. metaphone — Tính siêu khoá âm thanh của 1 chuỗi 33. money_format — Định dạng 1 số như 1 chuỗi tiền tệ 34. nl_langinfo — Ngôn ngữ truy vấn và biên tập thông tin 35. nl2br — Chèn 1 dòng ngắt HTML trước tất cả những dòng mới trong 1 chuỗi 36. number_format($number, $decimals, $decimalpoint, $separator) — Định dạng số $number với hàng nghìn chữ số "; //1,000,000 echo number_format("1000000",2)."
"; //1,000,000.00 echo number_format("1000000",2,",",".");//1.000.000,00 ?> 37. ord — Trả lại giá trị ASCII của kí tự ";//104 by Grimes 6 echo ord("hello")."
";//104 ?> 38. parse_str — Phân tách chuỗi thành các biến số ";//Peter echo $age;//43 ?> 39. print — In ra 1 chuỗi 40. printf — In ra 1 chuỗi được định dạng 41. quoted_printable_decode — Chuyển 1 chuỗi có thể in trích dẫn sang 1 chuỗi 8 bit.(Giải mã) 42. quoted_printable_encode — Chuyển 1 chuỗi có thể in trích dẫn sang 1 chuỗi 8 bit. 43. quotemeta — Trích dẫn kí tự đặc biệt 44. rtrim — Loại bỏ các ký tự ở cuối chuỗi, mặc định loại bỏ tất cả khoảng trắng ở cuối chuỗi. "; echo rtrim($str,"World!"); ?> 45. setlocale — Thiết lập vị trí thông tin "; echo setlocale(LC_ALL,NULL); //English_United States.1252 ?> 46. sha1_file — Mã hoá sha1 1 file 47. sha1 — Mã hóa chuỗi dạng sha1 48. similar_text — Cho số kí tự giống nhau của 2 chuỗi 49. soundex — Tính khoá chỉ âm của 1 chuỗi 50. sprintf — Trả lại 1 chuỗi được định dạng 51. sscanf — Phân tách chuỗi theo 1 định dạng 52. str_getcsv(string,separator,enclosure,escape) — Parse a CSV string into an array 53. str_ireplace — Thay thế ngược lại khi xâu đã bị thay thế bằng str_replace(). 54. str_pad — Tăng độ dài của chuỗi với các ký tự mới 55. str_repeat — cho phép lặp lại chuỗi $str theo $n lần 56. str_replace — tìm kiếm và thay thế trong chuỗi: 57. str_rot13 — Thực hiện mã hoá theo rot 13 trên 1 xâu "; echo str_rot13("Uryyb Jbeyq");//Hello World ?> 58. str_shuffle — sắp xếp ngẫu nhiên thứ tự các ký tự trong chuỗi 59. str_split — Cắt chuỗi thành các phần tử của mảng H [1] => e [2] => l [3] => l [4] => o ) ?> 60. str_word_count — Đếm tổng số từ có trong chuỗi 61. strcasecmp — Binary safe case-insensitive string comparison 62. strchr — Alias of strstr 64. strcoll — Locale based string comparison "; setlocale (LC_COLLATE, 'en_US'); echo strcoll("Hello World!","Hello World!");//0 ?> 65. strcspn — Find length of initial segment not matching mask by Grimes 9 66. strip_tags — để loại bỏ các thẻ HTML có trong chuỗi world!");//Hello world! ?> 67. stripcslashes — hiển thị chuỗi không có các ký tự gạch chéo được tạo bởi hàm addcslashes 68. stripos — Find the position of the first occurrence of a case-insensitive substring in a string 69. stripslashes — hiển thị chuỗi không có các ký tự gạch chéo được tạo bởi hàm addslashes 70. stristr — Case-insensitive strstr 71.strlen($str) — Đếm tổng số ký tự có trong chuỗi 72. strnatcasecmp — Case insensitive string comparisons using a "natural order" algorithm "; echo strnatcasecmp("10Hello world!","2Hello WORLD!"); // 1 ?> 73. strnatcmp — String comparisons using a "natural order" algorithm "; echo strnatcmp("10Hello world!","2Hello world!");// 1 ?> 74. strncasecmp — Binary safe case-insensitive string comparison of the first n characters 75.strncmp — Binary safe string comparison of the first n characters by Grimes 10 [...]...< ?php echo strncmp("Hello world!","Hello earth!",6);//0 ?> 76 strpbrk — Search a string for any of a set of characters < ?php echo strpbrk("Hello world!","oe");//ello world! ?> 77 strpos — Tìm vì trí xuất hiện đầu tiên của $chuoi_tim trong chuỗi $str < ?php echo strpos("I love php, I love php too!", "php" );//7 ?> 78 strrchr — Find the last occurrence of a character in a string < ?php echo strrchr("Hello... strrev — Reverse a string < ?php echo strrev("Hello World!");// !dlroW olleH ?> 80 strripos — Find the position of the last occurrence of a case-insensitive substring in a string < ?php echo strripos("I love php, I love php too!", "PHP" );//19 ?> 81 strrpos — Find the position of the last occurrence of a substring in a string < ?php echo strrpos("I love php, I love php too!", "php" );//19 ?> 82 strspn — Finds... lần xuất hiện chuỗi con < ?php echo substr_count("Hello world The world is nice","world");//2 ?> 90 substr_replace — thay thế một đoạn văn bản trong phạm vi một đoạn của xâu kí tự < ?php echo substr_replace("Hello","world",0);// world ?> 91 substr — tách chuỗi con từ một chuỗi < ?php echo substr("Hello world",6);// world ?> 92 trim — Loại bỏ những khoảng trắng ở đầu và cuối của chuỗi < ?php $str = "Hello... initial segment of a string consisting entirely of characters contained within a given mask < ?php echo strspn("Hello world!","kHlleo");//5 ?> 83 strstr — Tách ra một chuỗi con từ vị trí đầu tiên của chuỗi cho trước cho đến cuối chuỗi < ?php echo strstr("Hello world!","world");//world! ?> 84 strtok — Tokenize string < ?php $string = "Hello world Beautiful day today."; $token = strtok($string, " "); while ($token... chữ thường < ?php echo strtolowper("HELLO WORLD!");// hello world! ?> 86 strtoupper — Chuyển tất cả ký tự sang chữ in hoa < ?php echo strtoupper("Hello WORLD!");// HELLO WORLD! ?> 87 strtr — chuyển đổi kí tự theo một qui tắc nào đó < ?php echo strtr("Hilla Warld","ia","eo");//Hello World ?> 88 substr_compare — Binary safe comparison of two strings from an offset, up to length characters < ?php echo substr_compare("Hello... trim($str,"Hed!"); /* 12 by Grimes Hello World! llo Worl */ ?> 93 ucfirst — Viết hoa kí tự đầu tiên của chuỗi < ?php echo ucfirst("hello world!");// Hello world! ?> 94 ucwords — Viết hoa kí tự đầu tiên của mỗi từ < ?php echo ucwords("hello world");//Hello World ?> 95 vfprintf — Write a formatted string to a stream < ?php $number = 9; $str = "Beijing"; $file = fopen("test.txt","w"); echo vfprintf($file,"There are... test.txt nội dung “There are 9 million bicycles in Beijing.” ?> 96 vprintf — Output a formatted string < ?php $number = 9; $str = "Beijing"; vprintf("There are %u million bicycles in %s.",array($number,$str)); //There are 9 million bicycles in Beijing ?> 97 vsprintf — quai lại một xâu định dạng < ?php $number = 9; $str = "Beijing"; $txt = vsprintf("There are %u million bicycles in %s.",array($number,$str));... vsprintf("There are %u million bicycles in %s.",array($number,$str)); echo $txt;// There are 9 million bicycles in Beijing ?> 98 wordwrap — chia xâu kí tự ra thành các sâu con nhờ một kí tự xác định < ?php $str = "An example of a long word is: Supercalifragulistic"; echo wordwrap($str,15,"\n"); /* An example of a long word is: Supercalifragulistic */ ?> 13 by Grimes

- Xem thêm -

Xem thêm: Xử lí chuỗi trong PHP, Xử lí chuỗi trong PHP,