PHP 处理字符串的代码片段
来源:互联网 发布:help desk是什么软件 编辑:程序博客网 时间:2024/05/16 15:22
移除html 标签:$text = strip_tags($input, "");
返回 $start 和 $end 之间的文本
function GetBetween($content,$start,$end){ $r = explode($start, $content); if (isset($r[1])){ $r = explode($end, $r[1]); return $r[0]; } return '';}
将字符串中的url 转换成链接:
$url = "Jean-Baptiste Jung (http://www.webdevcat.com)";$url = preg_replace("#http://([A-z0-9./-]+)#", '<a href="http://www.catswhocode.com/blog/$1" style="font-size: 12px; vertical-align: baseline; background-color: transparent; margin: 0px; padding: 0px; color: #3777af; text-decoration: none; font-weight: bold">$0</a>', $url);
删除字符串中的URL:
$string = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $string);
解析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;}
从字符串中提取 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.com test8@ example.org test9@!foo!.org foobar';print_r(extract_emails($test_string));
- PHP 处理字符串的代码片段
- 常用字符串处理代码片段
- 实用的PHP代码片段
- PHP 常用的代码片段
- PHP 处理字符串的几段代码
- 一些有关图像处理的代码片段
- 10 个有用的 PHP 代码片段
- 10 个救命的 PHP 代码片段
- 10 个救命的 PHP 代码片段
- 10 个救命的 PHP代码片段
- 10 个救命的 PHP 代码片段
- 10个救命的PHP代码片段
- 十个超级有用的PHP代码片段
- 10个好用的PHP代码片段
- 十个超级有用的PHP代码片段
- 十个超级有用的PHP代码片段
- 十个超级有用的PHP代码片段
- 10 个实用的PHP代码片段
- 扩大VMware虚拟机中linux硬盘空间
- 屏蔽浏览器的地址栏和菜单栏,这样可以使系统看起来更正规 .
- 应用程序出现乱码解决方案
- c#直接对计算机的控制面板等调用
- 找出单向链表的倒数第m个元素
- PHP 处理字符串的代码片段
- Iphone 技巧
- 找回对计算机操作系统架构的深层理解——深入体验世界上最强大,最稳定的操作系统AIX UNIX
- Files in Xcode Project
- android应用程序安装后自动打开
- Android自动测试之MonkeyRunner介绍
- end tag for "select" which is not finished
- Linux下进程通讯方式
- 被国人误传了几千年的八句俗语