如何正确地爆炸字符串

时间:2014-08-22 08:49:00

标签: php string

如何爆炸字符串,例如

#heavy / machine gun #test

只能获得"heavy""test"

我尝试过爆炸,但到目前为止我只得到了#34; heavy / machine gun"和" test"

提前致谢, 雷米。

3 个答案:

答案 0 :(得分:1)

爆炸的替代方案:

$str = "#heavy / machine gun #test";
preg_match_all('/#([^\s]+)/', $str, $matches);
var_dump($matches[1]);

这基本上可以找到给定字符串中的所有主题标签。

答案 1 :(得分:0)

重新爆炸你的"首先"在重要的空间中找到重要的空间仅

$heavy = explode (' ', $my_previous_explode[1]); // I guessed you exploded on '#', so array index = 1

答案 2 :(得分:0)

在这种情况下,正则表达式显然更强大,但只是为了笑:

$str = '#heavy / machine gun #test';

$arr = array_filter(array_map(function($str){
    return strtok($str, ' ');   
}, explode('#', $str)));

» example