function - How to grab number after a word or symbol in PHP? -
i want grab text php example, there data "the apple=10" , want grab only numbers data looks that. mean, number's place after 'equals'.
and problem number source can 2 or 3 characters or on other word inconstant.
please me solve them :)
$string = "apple=10 | orange=3 | banana=7"; $elements = explode("|", $string); $values = array(); foreach($elements $element) { $element = trim($element); $val_array = explode("=", $element); $values[$val_array[0]] = $val_array[1]; } var_dump($values);
output:
array(3) { ["apple"]=> string(2) "10" ["orange"]=> string(1) "3" ["banana"]=> string(1) "7" }
hope thats how need :)
Comments
Post a Comment