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 1039327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:05:09+00:00 2026-05-16T15:05:09+00:00

Im creating a list of Twitter results in PHP, im already using PHP to

  • 0

Im creating a list of Twitter results in PHP, im already using PHP to turn text links in the string returned into clickable links rather than plain text.

In some of the Twitter results the string contains hash tags, simply text prepended with the # character.

What i would like to do is take the hastag and convert it into a clickable link.

For instance:

Hello my name is Dan, and im working with the #twitter api

Which I want to turn into:

Hello my name is Dan, and im working with the <a href="http://search.twitter.com/search?q=%23twitter">#twitter</a> api

Notice that in the URL I have to change the # to %23 – I think encode or decode.

Also….

Im already using the following code to create clickable links within the string, is it possible to combine the two RegEx’s?

Here is my PHP to convert links to clickable links:

            //Convert links in string to links
            preg_match('/(http:\/\/[^\s]+)/', $row["content"], $text);
            $hypertext = "<a target='_blank' href=\"". $text[0] . "\">" . $text[0] . "</a>";
            $newString = preg_replace('/(http:\/\/[^\s]+)/', $hypertext, $row["content"]);
  • 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-16T15:05:10+00:00Added an answer on May 16, 2026 at 3:05 pm
    $str = preg_replace('/\#([a-z0-9]+)/i', '<a href="http://search.twitter.com/search?q=%23$1">#$1</a>', $str);
    

    EDIT

    In terms of the two different patterns, just do:

    $str = preg_replace(array($url_pattern, $hash_pattern), array($url_replacement, $hash_replacement), $str);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a list (a text file) of all the directories recursively using
I am creating a list of links using a knockout binding: The Javascript and
I'm having troubles with creating a simple list (some expandable lists are already working).
I have the code below. The line string content = twitterMsg.text; is creating the
I'm creating a user input where I want them to list links as well
I've been tasked with creating a list of all possibilities using data in 8
I'm creating a list of pictures using a ListView and the photos are of
I have the following ListView : and I'm creating a List<string> of the items
im creating a list to update a MySql db with values form text boxes,
So I am creating a list of lines in a text file like this:

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.