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 Quote Link to comment Share on other sites More sharing options...
avshelestov Posted October 20, 2014 Share Posted October 20, 2014 (edited) Try, <?php $items = preg_match_all("!Luas\s+Bangunan\s{0,}:\s{0,}(\d+)!si", $your_text); Edited October 20, 2014 by avshelestov Quote Link to comment 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 Quote Link to comment 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]); Quote Link to comment Share on other sites More sharing options...
Solution Psycho Posted October 20, 2014 Solution 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(). Quote Link to comment Share on other sites More sharing options...
b4druz4lsyihab Posted October 21, 2014 Author Share Posted October 21, 2014 OK Guys Problem Resolved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.