3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $message = " [xxxStudent.address_1xxx][xxxStudent.address_2xxx][xxxStudent.address_3xxx] [xxxStudent.townxxx] [xxxStudent.countyxxx] [xxxStudent.postcodexxx] [xxxStudent.country_iso_2xxx]"; preg_match_all('/\[xxx(\w+[\.+\w+]+)xxx\]/', $message, $tags, PREG_SET_ORDER); foreach ($tags as $tag) { $tag_parts = explode('.', $tag[1]); if (count($tag_parts) == 1) { $tag_model = null; $tag_field = $tag[1]; } else if(count($tag_parts) == 2) { $tag_model = $tag_parts[0]; $tag_field = $tag_parts[1]; } var_dump($tag_model); var_dump($tag_field); }
Output for 4.3.0 - 7.1.0
string(7) "Student" string(9) "address_1" string(7) "Student" string(9) "address_2" string(7) "Student" string(9) "address_3" string(7) "Student" string(4) "town" string(7) "Student" string(6) "county" string(7) "Student" string(8) "postcode" string(7) "Student" string(13) "country_iso_2"