dongtiao2105 2017-03-03 00:21
浏览 140
已采纳

从数组中替换字符串

Currently I have an array

$cop_row = array('first_pulse1', 'second_pulse2');

what I want is to replace first_ & second_ from the cop_row array .

I am using this right now but it is not giving me the required result.

str_replace("first_","",$cop_row);

I am getting output

pulse1second_pulse2

What I want is

pulse1pulse2

Thanks for your concern.

  • 写回答

5条回答 默认 最新

  • dongyi7041 2017-03-03 00:33
    关注

    this will solve your problem.

    php > $x = ['first_pulse', 'second_pulse'];
    php > $q = preg_replace('/(\w+)_/i', '', $x);
    php > print_r($q);
    Array
    (
        [0] => pulse
        [1] => pulse
    )
    php > 
    

    http://php.net/manual/en/function.preg-match.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)
编辑
预览

报告相同问题?