3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function gethashtags($text) { //Match the hashtags preg_match_all('/(^|[^a-z0-9_])#([a-z0-9_]+)/i', $text, $matchedHashtags); $hashtag = ''; // For each hashtag, strip all characters but alpha numeric if(!empty($matchedHashtags[0])) { foreach($matchedHashtags[0] as $match) { $hashtag[] = preg_replace("/[^a-z0-9]+/i", "", $match); } } //to remove last comma in a string //return rtrim($hashtag, ','); return $hashtag; } //usage $text = "dfd'fdfd%#df"; print_R(gethashtags($text));
based on m264g
Output for 7.1.0 - 7.2.0
Fatal error: Uncaught Error: [] operator not supported for strings in /in/MAN8N:11 Stack trace: #0 /in/MAN8N(20): gethashtags('dfd'fdfd%#df') #1 {main} thrown in /in/MAN8N on line 11
Process exited with code 255.
Output for 5.3.18 - 7.0.20
Array ( [0] => df )