sp; } } } return $message; }
删除字符串中的URL
- $string = preg_replace(''/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i'', '''', $string);
将字符串转成SEO友好的字符串
- function slug($str){
- $str = strtolower(trim($str));
- $str = preg_replace(''/[^a-z0-9-]/'', ''-'', $str);
- $str = preg_replace(''/-+/'', "-", $str);
- return $str;
- }
解析 CSV 文件
- $fh = fopen("contacts.csv", "r");
- while($line = fgetcsv($fh, 1000, ",")) {
- echo "Contact: {$line[1]}";
- }
字符串搜索
- function contains($str, $content, $ignorecase=true){
- if ($ignorecase){
- $str = strtolower($str);
- $content = strtolower($content);
- }
- return strpos($content,$str) ? true : false;
- }
检查字符串是否以某个串开始
- function String_Begins_With($needle, $haystack {
- return (substr($haystack, 0, strlen($needle))==$needle);
- }
从字符串中提取email地址
- function extract_emails($str){
- // This regular expression extracts all emails from a string:
- $regexp = ''/([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i'';
- preg_match_all($regexp, $str, $m);
-
- return isset($m[0]) ? $m[0] : array();
- }
-
- $test_string = ''This is a test string...
-
- test1@example.org
-
- Test different formats:
- test2@example.org;
- <a href="test3@example.org">foobar</a>
- <test4@example.org>
-
- strange formats:
- test5@example.org
- test6[at]example.org
- test7@example.net.org.c
|