Home  >  Article  >  Backend Development  >  PHP: Regular expressions to process topic and object names in Weibo

PHP: Regular expressions to process topic and object names in Weibo

WBOY
WBOYOriginal
2016-07-25 09:10:071294browse
  1. $post_content = "@oschina and @twitter are studying using #PHP#'s #regularexpression# to filter topic and object names";
  2. $tag_pattern = "/#([^#|.]+)# /";
  3. preg_match_all($tag_pattern, $post_content, $tagsarr);
  4. $tags = implode(',',$tagsarr[1]);
  5. $user_pattern = "/@([a-zA-z0-9_ ]+)/";
  6. $post_content = preg_replace($user_pattern, '@$programmer chuangzi' , $post_content );
  7. $post_content = preg_replace($tag_pattern, '#$programmer chuangzi#< ;/a>', $post_content);
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn