我正在尋找一個例子來替換我的所有空間到「內聯」我認爲在英語中它是換行符。preg_replace/str_replace:內聯/換行
這是我的CSV文件的爲例:
"6543945";"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";"5017";"EnginSouhaite";"D";"1";"ne circule pas"
"6543945";"1111111111111111111111111111111111111111111111111100001010000101000010100001010000101000010100001010000101100010100001010000101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110001111111111111111111111111111111111111111000000000000000000000000000000000000";"5017";"EnginSouhaite";"D";"1";"Q JUSQU'AU 30/01/16 ; VE DF DU 31/01 AU 15/04/16 ; Q A PARTIR DU 17/04/16 (NE CIRCULE PAS 29,30,31/10/16)"
"6543946";"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";"5017";"EnginSouhaite";"D";"1";"ne circule pas"
"6543946";"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";"5017";"EnginSouhaite";"D";"1";"ne circule pas"
"6543945";"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";"5017";"EnginSouhaite";"D";"2";"ne circule pas"
"6543946";"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";"5017";"EnginSouhaite";"D";"2";"ne circule pas"
首先,我決定更換所有我的 '/「/' 爲空格(''),這樣的:
foreach($tableau as $row) {
$replace = preg_replace('/"/', ' ', $tableau[$i]);
echo $replace; ?> <br/> <?php
$i += 1;
}
這結果如下:
6543945
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
5017
EnginSouhaite
D
1
ne circule pas 6543945
1111111111111111111111111111111111111111111111111100001010000101000010100001010000101000010100001010000101100010100001010000101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110001111111111111111111111111111111111111111000000000000000000000000000000000000
5017
EnginSouhaite
D
1
Q JUSQU'AU 30/01/16
VE DF DU 31/01 AU 15/04/16
Q A PARTIR DU 17/04/16 (NE CIRCULE PAS 29,30,31/10/16) 6543946
正如你所看到的,我想(我喜歡)做一個內嵌因爲你可以看到一些像「654XXX」號碼是旁邊。 「ne circule pas」,對我來說,我需要這些數字是內聯的。
任何人都有解決方案?我有這樣的測試:
$replace2 = preg_replace(' ', '/$\n/',$replace);
這是錯誤的,我認爲這是一個很大的錯誤。
感謝
你說的「內聯」的意思是我也刪除了使用
$i
?你可以發表一個結果應該如何看的例子嗎? –您在我的文章中看到我的結果:例如,我的所有行都以「654xxx」之類的數字開頭。正如你所看到的,這一行:「Q PARTIR DU 17/04/16(NE CIRCULE PAS 29,30,31/10/16)6543946」是CSV文件的最後一行。我們可以在此行旁邊找到我的號碼「654xxx」。我需要將我的號碼放在我的線下,如下所示:(Q A .... NE CIRCULE PAS ...)
*換行符* \ n,654xxx。我希望你能理解(如果它不正確,我會編輯) –
嗯,你目前有結構化的CSV數據,所以我會利用它並使用類似'str_getcsv()'的東西解析它。然後,一旦將數據存儲在數組中,就可以直接打印任何您想要的數據。使用正則表達式可能會在某些情況下工作,但可能會在其他情況下中斷,所以最好直接處理CSV。 –