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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:44:22+00:00 2026-06-01T11:44:22+00:00

I have a little problem with some preg_replace functions in PHP. First I have

  • 0

I have a little problem with some preg_replace functions in PHP.
First I have $message = preg_replace("/\[img\](.*?)\[\/img\]/is", '<img src="$1" alt="" />', $message); for replacing [img]http://example.com/img.png[/img] with an image. But after that I also have a preg_replace which replaces URLs:

$message = preg_replace("/(?i)\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))/", '<a href="$1">title[$1]</a>', $message);

Is it possible to prevent that the URL within <img src='' is also replaces with a link? Like putting the URL replace function before the img preg_replace and changing the pattern that it won’t change URLs which are within BB-Code brackets?

Thanks for answers!

  • 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-01T11:44:23+00:00Added an answer on June 1, 2026 at 11:44 am

    UPDATE: Read update below.

    Sure. Use negative lookbehind to check what is behind.

    The syntax of it is similar to this:

    (?x)
    # Match abc if there is no ' or " behind
    (?<!['"]) abc
    

    For more details see perlre.


    UPDATE:

    It seems that it doesn’t really work. The trick literally means no ' or " behind, so regexp actually sees something like this (where matched string is in <>.

    "http://<example.com/img>.png"
    

    Instead of using this trick, you should read Ignore html tags in preg_replace instead. Sometimes regexp is not solution and that’s one of those cases.

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

Sidebar

Related Questions

I am writing some documentation and I have a little vocabulary problem: http://www.example.com/en/public/img/logo.gif is
I have a little problem with some jquery and http://www.mikage.to/jquery/jquery_history_noc.html The function works great,
I have a little problem. I had some JComboBox to a JDialog but they
i have a little problem implementing some serialization/deserialization logic. I have several classes that
I have a little problem. I have some text 23%, but I need some
I have a little problem. I need to do some little operations on quite
Guys i have a little problem, i tried to find some examples on GeoIP
I have a little problem with a selectbox that have to have some marked
I have a little problem, I'm trying to input some data that I get
I'm tring to learn C++ and I have a little problem. I have some

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.