递归问题,求助大神

浏览:171 发布日期:2020/03/23 分类:求助交流
public function readsizeAction () {
        $size = "S    42    18    98    66
M    46    20    \"1
0
0\"    70
L    48    22    \"10
4\"    72
XL    50    24    108    74
2XL    52    26    112    76";
        
        dump($this->lineFeed ($size, "\"",'\lf'));

        // stripos
        $new = str_replace(",", '_____', $size);
        $new = str_replace("\"", '\'', $new);
    }

    # 换行替换
    public function lineFeed ($str, $search, $replace) {

        # 获取首个查找字符位置
        $first = stripos ($str, $search);
        
        if ($first == true) {

            # 获取查找字符长度
            $strLen = strlen ($search);

            # 获取第二个查找字符位置
            $second = stripos ($str, $search, $first + $strLen);

            # 截取子字符串
            $substr = substr ($str, $first, $second - $first + $strLen);

            # 替换子字符串
            $substr = str_replace("\r\n", $replace, $substr);

            # 更新字符串
            $str = substr_replace($str, $substr, $first, $second - $first + $strLen);
            
            $this->lineFeed($str, $search, $replace);
        }

        return $str;
    }
最佳答案
评论( 相关
后面还有条评论,点击查看>>