I worked on a project and I'm trying to add the ability to detect hashtags, hashtags and url in a post by php. I wrote the code but it only returns links How I can return all three together?
 public function shortcut_links()
    {
    
    $post_text=   $this->post_text;
      $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
      $tag_text= "/@(\w+)/";
      $hashtag_text= "/#(\w+)/";
    
    if(preg_match_all($reg_exUrl, $post_text, $urls)) {
         foreach($urls[0] as $url){
            
               $post_text = preg_replace($reg_exUrl,'<a href='.$url.' >'. app("bitly")->getUrl($url).'</a>', $post_text);
          }
         
        return $post_text;
    }  elseif(preg_match_all($tag_text, $post_text, $urls)) {
        // make the urls hyper links,
        foreach($urls[0] as $url){
            
               $post_text = preg_replace($tag_text,'<a href='.$url.' >'.$url.'</a>', $post_text);
          }
          return $post_text;
     } 
   elseif(preg_match_all($hashtag_text, $post_text, $urls)) {
         foreach($urls[0] as $url){
            
               $post_text = preg_replace($hashtag_text,'<a href='.$url.' >'.$url.'</a>', $post_text);
          }
          return $post_text;
    } 
  else {
        return $post_text; 
    }
    return $post_text; 
    }
 
    