开发者

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
        )

)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜