b4druz4lsyihab Posted October 20, 2014 Share Posted October 20, 2014 how to take a word in php or explode based on luas Bangunan :xxxFor 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 More sharing options...
avshelestov Posted October 20, 2014 Share Posted October 20, 2014 Try, <?php $items = preg_match_all("!Luas\s+Bangunan\s{0,}:\s{0,}(\d+)!si", $your_text); Link to comment https://forums.phpfreaks.com/topic/291947-how-to-explode-word-using-php/#findComment-1494238 Share on other sites More sharing options...
b4druz4lsyihab Posted October 20, 2014 Author Share Posted October 20, 2014 Try, <?php $items = preg_match_all("!Luas\s+Bangunan\s{0,}:\s{0,}(\d+)!si", $your_text); Hy Newbie I've tried but did not work for me if you have any other suggestions for me anyway thanks for your answer Link to comment https://forums.phpfreaks.com/topic/291947-how-to-explode-word-using-php/#findComment-1494239 Share on other sites More sharing options...
Ch0cu3r Posted October 20, 2014 Share Posted October 20, 2014 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]); Link to comment https://forums.phpfreaks.com/topic/291947-how-to-explode-word-using-php/#findComment-1494264 Share on other sites More sharing options...
Psycho Posted October 20, 2014 Share Posted October 20, 2014 If you are wanting to find every instance of "Luas bangunan: xxx", then preg_match() is what you want. But, your title indicates you want to explode the string. If that is what you want to do, then you would use preg_split(). Link to comment https://forums.phpfreaks.com/topic/291947-how-to-explode-word-using-php/#findComment-1494275 Share on other sites More sharing options...
b4druz4lsyihab Posted October 21, 2014 Author Share Posted October 21, 2014 OK Guys Problem Resolved Link to comment https://forums.phpfreaks.com/topic/291947-how-to-explode-word-using-php/#findComment-1494298 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.