Jump to content

How to explode word using php


b4druz4lsyihab

Recommended Posts

how to take a word in php or explode based on luas Bangunan :xxx
For example I have string
$string =" Kondisi Properti : Bagus Dilengkapi Perabotan : Unfurnished Sertifikat : Lainnya Daya Listrik : 2200 Watt Kamar Tidur : 3/1 Kamar Mandi : 2/1 Luas Bangunan : 92 m² Luas Tanah : 126 m² Jumlah Lantai : -
Kondisi Properti : Bagus Sekali Dilengkapi Perabotan : Unfurnished Sertifikat : SHM - Sertifikat Hak Milik Daya Listrik : 6600 Watt Saluran Telepon : 1 Garasi : 3 Kamar Tidur : 4/1 Kamar Mandi : 3/1 Luas Bangunan : 300 m² Luas Tanah : 228 m² Jumlah Lantai : 2.5 ";

eg I want to take every "Luas bangunan: xxx"
Thanks

Link to comment
https://forums.phpfreaks.com/topic/291947-how-to-explode-word-using-php/
Share on other sites

avshelestov solution is correct. Although $your_text needs to be changed to $string and you need to add a third argument to preg_match_all to return the array of matches. Example code.

$items = preg_match_all("!Luas\s+Bangunan\s+:\s+(\d+)!si", $string, $matches); 

echo "Found $items instances of Luas Bangunan. The values are : ' . implode(', ', $matches[1]);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.