Merchant Id|Merchant|Website|Transaction In Period|Voids In Period|Gross Sales Amount|Total Commision in Period
9766|Mountains Plus Outdoor Gear|www.MPGear.com|1|0|88.91|8.89
12447|Meritline.com|www.meritline.com|5|0|52.86|3.71
16213|East Coast Fashions|www.discountstripper.com|1|0|32.27|3.23
17226|HRM USA|www.HeartRateMonitorsUSA.com|1|0|189.9|6.65
現在我得到上面的URL字符串現在我想該字符串基於分割符|
添加字符串分隔符從URL來在PHP
轉換爲數組,但每個新結束後出現了問題行沒有放置分隔符|
,所以我希望在每行結束後放置該分隔符。
注::所有列將被預定義,並且它將返回相同的所有時間請求。
我使用此代碼將該字符串轉換爲數組。如果將所有分隔符正確放置在字符串中,此代碼工作正常。
$NumColumns = 6;
$Delim = "|";
$data = array_chunk(explode($Delim,$contents), $NumColumns);
輸出會是這樣
Array
(
[0] => Array
(
[0] => Merchant Id
[1] => Merchant
[2] => Website
[3] => Transaction In Period
[4] => Voids In Period
[5] => Gross Sales Amount
[6] => Total Commision in Period
)
[1] => Array
(
[0] => 9766
[1] => Mountains Plus Outdoor Gear
[2] => www.MPGear.com
[3] => 1
[4] => 0
[5] => 88.91
[6] => 8.89
)
-----
----
)
...良好的工作,但沒有更多的\ n在字符串它的簡單strig不再\ n在那... –
@intekhabkhan在'\ \ n'被解釋爲一個換行符 - 它將匹配(並分割)每行的結尾。 – jcsanyi