Skip to content

Instantly share code, notes, and snippets.

@lenivene
Created October 21, 2017 23:08
Show Gist options
  • Save lenivene/90a406aa41a84810a27cced0f5128424 to your computer and use it in GitHub Desktop.
Save lenivene/90a406aa41a84810a27cced0f5128424 to your computer and use it in GitHub Desktop.
Get hash tag with php
<?php
/*
* First array return "tags" with hash, example: #Example
* Second "tag" return without hash, Example: Example
*
* @string $tweet The text
* @function preg_match_all | Pattern | @string $tweet (The text) | @array $tags (output array the tags)
* @return array $tags
*/
$twet = "But I must #explain to u how all this #mistaken idea of #denouncing pleasure and praising pain was born and I'll #give you a complete accout";
preg_match_all( "/#([\p{Pc}\p{N}\p{L}\p{Mn}]+)/u", $tweet, $tags );
echo "<pre>";
var_dump( $tags );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment