How to explode a string like
#heavy / machine gun #test
to get just "heavy" and "test" ?
"heavy"
"test"
I tried to explode, but so far I only got " heavy / machine gun " and " test "
heavy / machine gun
test
Thanks in advance, Jeremy.
Explosion alternative:
$str = "#heavy / machine gun #test"; preg_match_all('/#([^\s]+)/', $str, $matches); var_dump($matches[1]);
This will basically find all the hashtags in a given string.
Re-blast your "first" part in the spaces to get only the "heavy"
$heavy = explode (' ', $my_previous_explode[1]); // I guessed you exploded on '#', so array index = 1
The regex is obviously more robust in this case, but just for fun:
$str = '#heavy / machine gun #test'; $arr = array_filter(array_map(function($str){ return strtok($str, ' '); }, explode('#', $str)));
& raquo; Example