web,search,web2.0,1,seo,networking,social
web,search,web2.0,3,seo,networking,social
web,search,web2.0,4,seo,networking,social
如何从上面的行中删除1
,3
和4
?
答案 0 :(得分:2)
使用正则表达式,您可以替换“,[0-9] *,?”通过“,”也许
答案 1 :(得分:2)
var_dump(
implode(
',',
array_filter(
explode(',',$e),
create_function('$a','return !is_numeric($a);')
)
)
);
结果:
string(39) "web,search,web2.0,seo,networking,social"
string(39) "web,search,web2.0,seo,networking,social"
string(39) "web,search,web2.0,seo,networking,social"
细分:
expode()
array_filter()
create_function()
implode
答案 2 :(得分:1)
PHP有一个内置的csv解析器:http://php.net/manual/en/function.fgetcsv.php
我建议使用解析器,然后使用fputcsv()将数据写回。
答案 3 :(得分:0)
它的格式是否一样?
$string = ...;
$tab = explode(',', $string);
unset($tab[3]);
$string = implode(',', $tab);
答案 4 :(得分:0)
我假设每一行都是一个字符串
$mystring="web,search,web2.0,1,seo,networking,social";
$temp = explode(",", $mystring);
$mystring="";
for($i=0;$i<count($temp);$i++) {
if(is_int($temp[$i])==false)
$mystring+=$temp[$i];
if($i <count($temp)-1)
$mystring+=",";
}