How to seperate data in one variable php -
i have data store in 1 varible, how separate this:
$data="john doe 25yr london"
become this:
$name="john doe"; $age="25"; $city="london";
<?php $data="john doe 25yr london"; $arr = preg_split('/(?=\d)/', $data, 2); if(count($arr) == 2) { $name = trim($arr[0]); $city = trim(strstr($arr[1], ' ')); $age = trim(str_replace($city, '', $arr[1])); }
Comments
Post a Comment