我想创建一个标记系统,所以我想知道如何提取哈希词,即#tag然后将它们插入到数据库中,你能引导我去寻求帮助吗?感谢
答案 0 :(得分:3)
<?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...
?>
哪个会给你:
Array
(
[0] => Array
(
[0] => #string
[1] => #hash
[2] => #yessir
)
[1] => Array
(
[0] => string
[1] => hash
[2] => yessir
)
)