How do I fill an array like this:
array('0' => 'blabla','1' => 'blabla2')
from a string like this:
'#blabla foobar #blabla2'
using preg_match()
?
How do I fill an array like this:
array('0' => 'blabla','1' => 'blabla2')
from a string like this:
'#blabla foobar #blabla2'
using preg_match()
?
You should use preg_match_all()
for that:
preg_match_all('/#(\S+)/', $str, $matches, PREG_PATTERN_ORDER);
$matches = $matches[1];
$string = "#wefwe dcdfg qwe #wef";
preg_match_all('/#(\w+)/', $string, $matches);
var_dump($matches);
array(2) {
[0]=>
array(2) {
[0]=>
string(6) "#wefwe"
[1]=>
string(4) "#wef"
}
[1]=>
array(2) {
[0]=>
string(5) "wefwe"
[1]=>
string(3) "wef"
}
}
That is one way to do it :-)