原数据格式:
'ABC20231217043116afj6J0I6WV
ABC20231217043116dlSyOB5Tvx
ABC202312170431166EbL7BbYOm
ABC20231217043116troQuaKWzw
ABC20231217043116o7ZELjjF7E
ABC20231217043122FFp1CSPLQ2
ABC20231217043133uJIBKil3bC
ABC202312170431337z4bZwGJVS
ABC20231217043133fih3BSHqaK
ABC20231217043133EOtXxMbsqL
ABC20231217043136LvURmFoBP5
ABC20231217043136QXl2afhiza
ABC20231217043136IjwTFp21wG
ABC20231217043139tg4YrimXGB
ABC20231217043139qqOG7ubVxy
ABC20231217043139SXs006Fnyk
ABC20231217043139mtmjF3sB50
ABC20231217043140LyRPqcg6nh
ABC202312170431403aqkDklm2U
ABC20231217043143wRiyluA7NU
ABC20231217043143TllZ2xe4Zl
ABC20231217043143wA1TFBT1o0
ABC202312170431431ksVkXPJoY
ABC20231217043143BkviuduRH5
ABC20231217043143NyajBlEkcJ
ABC20231217043143u84WDf0U3C
ABC20231217043146zhY2PnVbtI
ABC202312170431461Jp27fonUU
ABC20231217043146V8mQYzhHyP'
处理后格式:
'ABC20231217043116afj6J0I6WV','ABC20231217043116dlSyOB5Tvx','ABC202312170431166EbL7BbYOm','ABC20231217043116troQuaKWzw','ABC20231217043116o7ZELjjF7E','ABC20231217043122FFp1CSPLQ2','ABC20231217043133uJIBKil3bC','ABC202312170431337z4bZwGJVS','ABC20231217043133fih3BSHqaK','ABC20231217043133EOtXxMbsqL','ABC20231217043136LvURmFoBP5','ABC20231217043136QXl2afhiza','ABC20231217043136IjwTFp21wG','ABC20231217043139tg4YrimXGB','ABC20231217043139qqOG7ubVxy','ABC20231217043139SXs006Fnyk','ABC20231217043139mtmjF3sB50','ABC20231217043140LyRPqcg6nh','ABC202312170431403aqkDklm2U','ABC20231217043143wRiyluA7NU','ABC20231217043143TllZ2xe4Zl','ABC20231217043143wA1TFBT1o0','ABC202312170431431ksVkXPJoY','ABC20231217043143BkviuduRH5','ABC20231217043143NyajBlEkcJ','ABC20231217043143u84WDf0U3C','ABC20231217043146zhY2PnVbtI','ABC202312170431461Jp27fonUU','ABC20231217043146V8mQYzhHyP'
代码
php
public function actionFormatConversion()
{
$_data = Yii::$app->request->post('data');
if(empty($_data)){
return $this->returnErrorApi('参数不能为空');
}
//把$_data分割成数组
$_data = explode("\n",$_data);
//把数组中的每个元素去掉多余的空格在加上''
$_data = array_map(function ($v){
$v = trim($v);
return "'".$v."'";
},$_data);
//在组合成字符串
$_data = implode(',',$_data);
var_dump($_data);
}