开发者

how can i extract words from a string and insert them into the database? Tagging

开发者 https://www.devze.com 2023-01-14 14:03 出处:网络
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! tha

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

精彩评论

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

关注公众号