21,886
社区成员
发帖
与我相关
我的任务
分享
$str =
'123[test] abc c1 c2 c3
456 def d1[test] d2 d3
789 ghi[sfjsldf] z1 z2 z3';
$str = preg_replace('/\[.*\]/','',$str);
echo "<pre>{$str}";
/*
//Output
123 abc c1 c2 c3
456 def d1 d2 d3
789 ghi z1 z2 z3
*/
$str =
'123[test] abc c1 c2 c3
456 def d1[test] d2 d3
789 ghi[sfjsldf] z1 z2 z3';
$ar = split("[\n\r]+",$str);
$arTMP = array();
foreach($ar as $v) $arTMP[] = explode(' ',$v);
function fmt($ar) {
foreach($ar as $k => $v) $ar[$k] = preg_replace('/\[.*\]/','',$v);
return $ar;
}
foreach($arTMP as $k => $v) $arTMP[$k] = implode(' ',fmt($v));
$str = implode("\n",$arTMP);
echo "<pre>{$str}";
/*
//Output
123 abc c1 c2 c3
456 def d1 d2 d3
789 ghi z1 z2 z3
*/
$str = '123[test] abc c1 c2 c3
456 def d1[test] d2 d3';
$ar = split("[\n\r]+",$str);
$ar1 = explode(' ',$ar[0]);
$ar2 = explode(' ',$ar[1]);
function fmt($ar) {
foreach($ar as $k => $v) $ar[$k] = preg_replace('/\[.*\]/','',$v);
return $ar;
}
$ar1 = fmt($ar1);
$ar2 = fmt($ar2);
$str = implode(' ',$ar1)."\n".implode(' ',$ar2);
echo "<pre>{$str}";
/*
//Output
123 abc c1 c2 c3
456 def d1 d2 d3
*/