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

  • Home
  • SEARCH
  • 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 710123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:34:48+00:00 2026-05-14T04:34:48+00:00

i am designing a site with a comment system and i would like a

  • 0

i am designing a site with a comment system and i would like a twitter like reply system.

The if the user puts @a_registered_username i would like it to become a link to the user’s profile.

i think preg_replace is the function needed for this.

$ALL_USERS_ROW *[‘USERNAME’] is the database query array for all the users and [‘USERNAME’] is the username row.

$content is the comment containing the @username

i think this should not be very hard to solve for someone who is good at php.

Does anybody have any idea how to do it?

  • 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-14T04:34:48+00:00Added an answer on May 14, 2026 at 4:34 am

    You want it to go through the text and get it, here is a good starting point:

    $txt='this is some text @seanja';
    
    $re1='.*?'; # Non-greedy match on filler
    $re2='(@)'; # Any Single Character 1
    $re3='((?:[a-z][a-z]+))';   # Word 1
    
    if ($c=preg_match_all ("/".$re1.$re2.$re3."/is", $txt, $matches))
    {
          $c1=$matches[1][0];
          $word1=$matches[2][0]; //this is the one you want to replace with a link
          print "($c1) ($word1) \n";
    }
    

    Generated with:

    http://www.txt2re.com/index-php.php3?s=this%20is%20some%20text%20@seanja&-40&1
    

    [edit]

    Actually, if you go here ( http://www.gskinner.com/RegExr/ ), and search for twitter in the community tab on the right, you will find a couple of really good solutions for this exact problem:

    $mystring = 'hello @seanja @bilbobaggins sean@test.com and @slartibartfast';
    $regex = '/(?<=@)((\w+))(\s)/g';
    $replace = '<a href='http://twitter.com/$1' target="_blank">$1</a>$3';
    preg_replace($regex, $replace, $myString);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While designing my site I am constantly faced with the issue of whether its
I'm designing a site with a fixed repeated background but can't work out why
I'm looking for best-practices for designing a site that with accessibility in mind. The
What are the topics we should pay attention while designing web site for Internet
I am designing a web site but it is behind a firewall and such
I have a large, hi-def JavaScript-intensive image banner for a site I'm designing. What
Designing a new system from scratch. I'll be using the STL to store lists
When designing LINQ classes using the LINQ to SQL designer I've sometimes needed to
When designing a database to use MVCC (Multi-Version Concurrency Control), you create tables with
While designing a table my colleague here says that I should avoid identity column

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.