0
我收到了一些字符串,其中一些字符串以=开头,最后以“”结尾。php preg_replace模式转换=“xxxxx”为xxxx
但有些只是数字和字母的组合。
是否有任何方法一次性去除=“和”?谢谢。
<?php
$items = ['0050','="1234P"','123','="2334"'];
for($i=0;$i<count($items);$i++){
//do something in the "convert" function
$items[$i]=convert($items[$i]);
}
//output: ['0050','1234P','123','2334'];
?>
是做到这一点。你有任何正则表达式的具体问题? –
为什么使用正则表达式? '函数convert($ value){return trim($ value,'='');}'或者跳过调用convert,直接对每个元素进行修剪 –
[trim()']的第二个参数(http ://us2.php.net/manual/en/function.trim.php)是你想修剪的字符的字符列表。 –