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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:49:27+00:00 2026-06-04T02:49:27+00:00

Hello everyone i have a problem I have a text $text = some and

  • 0

Hello everyone i have a problem
I have a text

$text = " some and text http://www.somelink2.com/html5.jpg and some text http://www.somelink.net/test/testjava/html5.html#fbid=QTb-X6fv5p1 some http://www.somelink4.org test and http://www.somelink3.org/link.html text and some text ";

i need to transform all text links http/s exept domains somelink3.org,somelink2.com they must be plain text

Something like this but with domains filter and not extention images:

function livelinked ($text){
        preg_match_all("#((http|https|ftp)://(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)|^(jpg)^#ie", $text, $ccs);
        foreach ($ccs[3] as $cc) {
           if (strpos($cc,"jpg")==false  && strpos($cc,"gif")==false && strpos($cc,"png")==false ) {
              $old[] = "http://".$cc;
              $new[] = '<a href="http://'.$cc.'" target="_blank">'.$cc.'</a>';
           }
        }
        return str_replace($old,$new,$text);
}

edit: this helped me :

$text =  preg_replace("~((?:http|https|ftp)://(?!site.com|site2.com|site3.com)(?:\S*?\.\S*?))(?=\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)~i",'<a href="$1" target="_blank">$1</a>',$text);  
  • 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-06-04T02:49:28+00:00Added an answer on June 4, 2026 at 2:49 am

    You can use a (?!...) negative lookahead assertion for such cases. Simply add (?!somelink3.org|somelink2.com) immediately after the protocol placeholder ://.

     #((http|https|ftp)://(?!domain1|domain2)(\S*?\.\S*?))....
    

    Also you shouldn’t use preg_match_all in combination with a clumsy str_replace as secondary step. Instead utilize preg_replace_callback and put all the logic in one function.

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

Sidebar

Related Questions

Hello everyone! I have a website which is http://www.urbanelementz.ca ... It's currently in development.
hello everyone I have some problem with understanding this piece of the code: import
Hello everyone I have some problem to grab movie title with regular expression. how
Hello everyone i have a problem in my application. The check in my check
Hello everyone I have a difficult problem with using BULK INSERT command when I
hello everyone i have a problem with my 3-tiers application i don't know how
Hello everyone~ I have a problem to solve~ I have created a server that
Hello everyone I have a problem I'll try to describe shortly In our application
Hello Everyone and Good Morning, I am working with the page: http://702wedding.com/live/ And it
Some details XAMPP 1.7.1 OS tested on vista and xp Hello everyone. I have

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.