substring - Getting data with substr dynamically in PHP -
i've got data:
204:7|209:8|210:10|211:11|220:1|225:6|226:5|
i want extract number after colon on each of bigger numbers, can single number when getting more double character number such 11 have increase substring range, if 6 example, display '6|' how make substr number no matter length number is?
your problem example shows why shouldn't use length related functions numbers related content.
explode
work given input though :
$str = "204:7|209:8|210:10|211:11|220:1|225:6|226:5|"; $str_array = explode ('|', $str); foreach ($str_array $sub_str) { echo explode(':', $sub_str)[1]; // edit : ok wanted part after ':' guess, [1]. }
as notified @praveenkumar , @hindmost, syntax works since php 5.5
on previous versions, use :
$str = "204:7|209:8|210:10|211:11|220:1|225:6|226:5|"; $str_array = explode ('|', $str); foreach ($str_array $sub_str) { $tmp = explode(':', $sub_str); echo $tmp[1]; }
Comments
Post a Comment