⑴ 几个有用的php字符串过滤,转换函数
explode — 使用一个字符串分割另一个字符串
array explode ( string $delimiter , string $string [, int $limit ] )
此函数返回由字符串组成的数组,每个专元素都是 string 的一个子属串,它们被字符串 delimiter 作为边界点分割出来。
<?php// 示例 1$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";$pieces = explode(" ", $pizza);echo $pieces[0]; // piece1echo $pieces[1]; // piece2 // 示例 2$data = "foo:*:1023:1000::/home/foo:/bin/sh";list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);echo $user; // fooecho $pass; // * ?>
⑵ php如何实现去掉某个字符串之后的内容
去掉某字符内容办法
strstr(string,string) = strchr(,) //从前面第一次出现某个字符串的地方截取到最后
strrchr(string,string) //从某个字符串从最后出现的位置截取到结尾
strpos(string,string[,int]) //某个字符串第一次出现的位置
strrpos(string,string) //某个字符串最后一次出现的位置
substr(string,int[,int]) //从指定位置开始截取字符串,可以指定截取的长度。strlen(string) //获取字符串的长度
⑶ php字符串过滤
^$str = preg_replace("/^.+=(.+)$/", "新内容\\1", $str); //过滤等于号前面的所有字符串(包括等于号)
$str = preg_replace("/^(.+)=.+$/", "\\1"."新内容", $str); //过滤等于号后面的所有字符串(包括等于号)
⑷ php 怎么过滤后url后面的缀名
$_GET['id']='sdfsf.5.jpg';
$new_str= strrev($str);
$new_str1=substr($new_str,strpos($new_str, ".")+1);
echo strrev($new_str1)
⑸ PHP字符串过滤
可以用正则实现抄。给定字符串的规律是3冒号1分号中,前两个冒号之前是数字,需要的是第三个冒号与分号之前的部分。可如下处理:
<?php
$string = "6939376:28407:包装方式:包装;5392114:75367881:重量(g):500;20000:7343430:品牌:蒙园;";
preg_match_all("/[^:\d]+:[^;]+;/", $string, $out);
$rst = implode("", $out[0]);
echo $rst;
?>
$rst为"包装方式:包装;重量(g):500;品牌:蒙园;"。已经测试是可行的(php5),如有问题欢迎继续交流
⑹ php怎样过滤掉特殊字符啊 ☺
过滤掉特殊字符,可以考虑使用字符串替换的方法,在php中替换字符效率最高也是最简单字符替换函数str_replace函数。
使用方法:str_replace(find,replace,string,count)
参数说明:
find 必需。规定要查找的值。
replace 必需。规定替换 find 中的值的值。
string 必需。规定被搜索的字符串。
count 可选。一个变量,对替换数进行计数。
实例:
str_replace("iwind","kiki","iloveiwind,iwindsaid");
将输出 "i love kiki, kiki said"
当然你也可以采取正则替换的方法,该函数是preg_replace
⑺ PHP字符串中特殊符号的过滤方法介绍
本篇文章主要是对PHP字符串中特殊符号的过滤方法进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助
有时候我们会遇到过滤字符串中特殊字符的问题,本文提供了一个处理特殊字符串的方法,可能有遗漏,如果读者发现了可以
代码如下:
function
strFilter($str){
$str
=
str_replace('`',
'',
$str);
$str
=
str_replace('·',
'',
$str);
$str
=
str_replace('~',
'',
$str);
$str
=
str_replace('!',
'',
$str);
$str
=
str_replace('!',
'',
$str);
$str
=
str_replace('@',
'',
$str);
$str
=
str_replace('#',
'',
$str);
$str
=
str_replace('$',
'',
$str);
$str
=
str_replace('¥',
'',
$str);
$str
=
str_replace('%',
'',
$str);
$str
=
str_replace('^',
'',
$str);
$str
=
str_replace('……',
'',
$str);
$str
=
str_replace('&',
'',
$str);
$str
=
str_replace('*',
'',
$str);
$str
=
str_replace('(',
'',
$str);
$str
=
str_replace(')',
'',
$str);
$str
=
str_replace('(',
'',
$str);
$str
=
str_replace(')',
'',
$str);
$str
=
str_replace('-',
'',
$str);
$str
=
str_replace('_',
'',
$str);
$str
=
str_replace('——',
'',
$str);
$str
=
str_replace('+',
'',
$str);
$str
=
str_replace('=',
'',
$str);
$str
=
str_replace('|',
'',
$str);
$str
=
str_replace('',
'',
$str);
$str
=
str_replace('[',
'',
$str);
$str
=
str_replace(']',
'',
$str);
$str
=
str_replace('【',
'',
$str);
$str
=
str_replace('】',
'',
$str);
$str
=
str_replace('{',
'',
$str);
$str
=
str_replace('}',
'',
$str);
$str
=
str_replace(';',
'',
$str);
$str
=
str_replace(';',
'',
$str);
$str
=
str_replace(':',
'',
$str);
$str
=
str_replace(':',
'',
$str);
$str
=
str_replace(''',
'',
$str);
$str
=
str_replace('"',
'',
$str);
$str
=
str_replace('“',
'',
$str);
$str
=
str_replace('”',
'',
$str);
$str
=
str_replace(',',
'',
$str);
$str
=
str_replace(',',
'',
$str);
$str
=
str_replace('<',
'',
$str);
$str
=
str_replace('>',
'',
$str);
$str
=
str_replace('《',
'',
$str);
$str
=
str_replace('》',
'',
$str);
$str
=
str_replace('.',
'',
$str);
$str
=
str_replace('。',
'',
$str);
$str
=
str_replace('/',
'',
$str);
$str
=
str_replace('、',
'',
$str);
$str
=
str_replace('?',
'',
$str);
$str
=
str_replace('?',
'',
$str);
return
trim($str);
}
⑻ php过滤字符串
用正则表达式替换。
因为你没有详细说明,所以我无法给你演示,找一本版正则表达式手册,权如果你熟悉php,应该很容易看懂,在php里面有正则表达式的相关函数,比如替换/匹配都很方便。
以下是几个例子:
正则表达式说明
/\b([a-z]+) \1\b/gi一个单词连续出现的位置
/(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/将一个URL解析为协议、域、端口及相对路径
/^(?:Chapter|Section) [1-9][0-9]{0,1}$/定位章节的位置
/[-a-z]/A至z共26个字母再加一个-号。
/ter\b/可匹配chapter,而不能terminal
/\Bapt/可匹配chapter,而不能aptitude
/Windows(?=95 |98 |NT )/可匹配Windows95或Windows98或WindowsNT,当找到一个匹配后,从Windows后面开始进行下一次的检索匹配。
⑼ php 去掉字符串中的一段字符串
可以用str_replace函数去掉字符串中的一段字符串。
1、新建php程序,定义一个变量,然后将一段字符串赋值给这个变量并将值输出: