php去除一些文字

来源:百度知道 编辑:UC知道 时间:2024/09/20 23:42:43
现在我的数据库中有很多的公司名称,有些包含“青岛”“青岛市”“公司”“有限公司”“厂”“企业”等等一些词,我想去除这些词语,请大家帮我写个函数,非常感谢

<?php

function placestr($array,$string) {
if(!is_array($array)) return false;
if(empty($string) || $string=='') return false;
$count = count($array);
$newstr= $string;
for($i=0; $i<$count; $i++) {
$newstr = str_replace($array[$i], '', $newstr);
}
return $newstr;
}
$array = array("青岛市","青岛","有限公司","公司","厂","企业");
//string 是你的内容字段。
$resutl= placestr($array, $string)
?>

用下面样子的语句进行替换:
$s=str_replace('青岛','',$s);

$s = ~s/青岛|公司//g;
用正则表达式吧

$s=str_replace('青岛','',$s);
$s=str_replace('青岛市','',$s);
$s=str_replace('公司','',$s);
$s=str_replace('有限公司','',$s);
$s=str_replace('厂','',$s);
$s=str_replace('企业','',$s);