how can i extract words from a string and insert them into the database? Tagging
i wanted to create a tagging system, so i want to know how can i ext开发者_开发问答ract the hashed words i.e #tag and then insert them into the database, can you lead me to a toturial or help out! thanks
<?php
$string = 'this is a #string with #hash tags #yessir';
preg_match_all('/#([a-z0-9-_]+)/', $string, $matches);
print_r($matches);
// Do your database stuff here...
?>
Which will give you:
Array
(
[0] => Array
(
[0] => #string
[1] => #hash
[2] => #yessir
)
[1] => Array
(
[0] => string
[1] => hash
[2] => yessir
)
)
精彩评论