我想用PHP循環數據組,但我的問題是我想將所有semicolons (;)
和換行符enterspace
替換爲逗號(,)
。循環播放也必須從我的評論開始(<- Record Start)
& (record end)
。在循環中將字符串轉換爲逗號在PHP中
數據:
P;A251213027;142G;3142831233555;10062014:0420;101;3000.00;0.00; (<- Record Start)
050;0;0;0;N;3000.00;0.00;0.00;Y;;;2PH_02
C;LOIVINO;ICIO
C;1AN INT;MALY;MAR;;;MAL
C;GRSE;LPES
C;B;PHILIPPINES;N0203004177;;Y;12112015;12111977;PHILIPPINES;PHILIPPINES
C;Y;09064656319;DO NOT HAVE;DO NOT HAVE;FRIEND;;
C;
C;;;B125 LO259;QU2TY;;PH (<- End Record)
編輯 我發現其中記錄必須開始和結束。
這裏是我的代碼
// break each result set
$parts = explode('C;', $str);
foreach($parts as $part){
// C;;; is not in the $parts array, if you want it in the result
// add it here
$res = explode(';', $part);
foreach($parts as $part){
// you have each line of the result
}
}
嘗試使用 - str_replace(';',',',$ var) –
我沒有得到您的要求。你有多個'C;'在那裏,爲什麼有些「結束循環」,有些不是? – Devon
您已第二次編輯了您的示例。你確定這是你想要的嗎?你是否嘗試過海報提供的樣本? –