explode implode
explode , implode
explode belirlediğiniz karekter yada karekterlerle parçalamaya yarayan güzel ve çok kullandığımız bir php fonksiyondur. Bir örnekle açıklayalım.
$degisken = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
$parcala = explode("o", $degisken);
print_r($parcala);
/*
Array
(
[0] => L
[1] => rem Ipsum is simply dummy text
[2] => f the printing and typesetting industry. L
[3] => rem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unkn
[4] => wn printer t
[5] =>
[6] => k a galley
[7] => f type and scrambled it t
[8] => make a type specimen b
[9] =>
[10] => k. It has survived n
[11] => t
[12] => nly five centuries, but als
[13] => the leap int
[14] => electr
[15] => nic typesetting, remaining essentially unchanged. It was p
[16] => pularised in the 1960s with the release
[17] => f Letraset sheets c
[18] => ntaining L
[19] => rem Ipsum passages, and m
[20] => re recently with deskt
[21] => p publishing s
[22] => ftware like Aldus PageMaker including versi
[23] => ns
[24] => f L
[25] => rem Ipsum.
)
*/
tam tersi de mümkündür. implode ile de birleştirme yapabiliriz. Biraz önce parçaladığımız içeriği tekrar birleştirdik. Yine o harfini referans aldık ve sanki $degiskenimiz hiç değişmemiş oldu.
$birlestir = implode("o", $parcala);
echo $birlestir;
/*
çıktısı : Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
*/