2014-06-08 52 views
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']; 
?> 
+0

是做到这一点。你有任何正则表达式的具体问题? –

+3

为什么使用正则表达式? '函数convert($ value){return trim($ value,'='');}'或者跳过调用convert,直接对每个元素进行修剪 –

+1

[trim()']的第二个参数(http ://us2.php.net/manual/en/function.trim.php)是你想修剪的字符的字符列表。 –

回答

0

您可以preg_replace();

$items = array('0050','="1234P"','123','="2334"'); 

$result = preg_replace("/[=\"]/", "", $items); 

print_r($result);