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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:05:31+00:00 2026-05-28T16:05:31+00:00

The code below detects URL’s in a body of text and wraps them in

  • 0

The code below detects URL’s in a body of text and wraps them in tags.

 function link_it($text)  
    {

        $text= preg_replace("/(^|[\n ])([\w]*?)((ht|f)tp(s)?:\/\/[\w]+[^ \,\"\n\r\t<]*)/is", "$1$2<a href=\"$3\" >$3</a>", $text);  
        $text= preg_replace("/(^|[\n ])([\w]*?)((www|ftp|m)\.[^ \,\"\t\n\r<]*)/is", "$1$2<a href=\"http://$3\" >$3</a>", $text);  
        $text= preg_replace("/(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+)+)/i", "$1<a href=\"mailto:$2@$3\">$2@$3</a>", $text);  
        return($text);  
    }  

I would like it so that if a user types a url (detected via the function above) with a specific domain of (flickr|youtube|vimeo) etc the function adds the class “embed to the tag template, otherwise it leaves it classless.

e.g.

‘this is the website http://www.google.com&#8217; would return:

this is the website <a href="http://www.google.com">http://www.google.com</a>

but ‘this is the website http://www.flickr.com&#8217; would return

this is the website <a href="http://www.flickr.com" class="embed">http://www.flickr.com</a>

How would I go about adding this into the function?

  • 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-28T16:05:32+00:00Added an answer on May 28, 2026 at 4:05 pm

    Use preg_replace_callback() for this. In your callback function, match the URL against some set of URLs that should have the embed class, and if it matches, include the class attribute definition, otherwise don’t.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is my code var tweetid = '133450847156838400'; $.ajax({ dataType: jsonp, url: http://api.twitter.com/1/statuses/show/+tweetid+.json?include_entities=1&callback=?, error:function(xhr,
right now the jsp code will create html like below <a href=xxxxxx> <img width=143
I want to detects directories im my computers.but when I write below code ,
I need a working Regex code in C# that detects plain text urls (http/https/ftp/ftps)
Code below is not working as expected to detect if it is in design
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code below is working well as long as I have class ClassSameAssembly in same
Code below is used to save PostgreSql database backup from browser in Apache Mono
The code below is meant to insert values into a MySQL Database if the
The code below shows a sample that I've used recently to explain the different

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.