Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6091815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:22:16+00:00 2026-05-23T12:22:16+00:00

So I am using a preg_match to get any text after a # up

  • 0

So I am using a preg_match to get any text after a # up until a space out of a string. However if there are multiple occasions of it in the string it will only return the first one. This is what I have so far

$text = '#demo1 #demo2 some text #blah2';
$check_hash = preg_match("/([#][a-zA-Z-0-9]+)/", $text, $hashtweet);
foreach ($hashtweet as $ht){
echo $ht;
}

The echo $ht; outputs #demo1#demo1 when it should output all 3 of the words with # in front. Any help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:22:16+00:00Added an answer on May 23, 2026 at 12:22 pm

    You want to use preg_match_all.

    Example:

    <?php 
    
    $text = '#demo1 #demo2 some text #blah2';
    $check_hash = preg_match_all("/([#][a-zA-Z-0-9]+)/", $text, $hashtweet);
    foreach ($hashtweet[1] as $ht){
      echo $ht;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a long long text contains multiple url. BUT there is only one
first, this is using preg. String I'm trying to match: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa b c d
I'm using preg_replace_callback to substitute particular tokens within the string. But apart from actual
I'm trying to minify multiple CSS files using preg_replace() . Actually, I'm only trying
I am having an issue removing %3Cbr+%2F%3E from my string using the preg_replace function.
So this is the problem, Im using preg_match, to match current URI from browser,
$str = check-me-01; if(preg_match(#(\d){0,}$#,$str)) { $strArr = preg_split(#(\d){0,}$#,$str,2); print_r($strArr); } I am using above
Possible Duplicate: parse youtube video id using preg_match Grab the video ID only from
I am using this PHP function to grab all <img> tags within any given
I'm trying to isolate the percentage value in a string of text. This should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.