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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:30:57+00:00 2026-06-11T15:30:57+00:00

Here’s a weird wrench that I’m dealing with at the moment. I’ve been back

  • 0

Here’s a weird wrench that I’m dealing with at the moment. I’ve been back and forth with it, using a variety of regular expressions, spacing and quote variations but there seems to only be an issue with the placement of the closing </a> tag.

I’ve built a RegEx parser (I know) to grab tags from HTML output and trigger custom closures for each from a library of what we call “shortcodes”. It’ll just swap out the tag for the closure’s return value, and if the closure doesn’t exist, leave the tag in place.

When that </a> is placed on the same line as the tag I’m grabbing, it causes preg_replace_callback to fail. When I add a line break, everything works flawlessly. We’re using these tags all over the place as a central part of our template system and they’re working wonderfully in every other instance.

So my question is… why?! Is this a bug or am I the bug?

EDIT: Updated pattern to limit reluctancy. Closing </a> tag still kills the process. (@Alan Moore)

EDIT 2: So, the regex was the culprit. It was pulling in the content beyond the tag on the same line on some cases, but this pattern solved the problem – '#\[\s*(\w[^\]\s]*)(.*?)\s*\]#i'.

Failing HTML

<div>
    <a href="[ make_url post_id='200' ]">Some Link</a>
</div>

Successful HTML

<div>
    <a href="[ make_url post_id='200' ]">
        Some Link
    </a>
</div>

or

<div>
    <a href="[ make_url post_id='200' ]">Some Link
    </a>
</div>

PHP

Nothing fancy, and even when I dumb it down to the basics it still fails.

$content = 'HTML output from an output buffer';
//$old_pattern = '#\[\s*?(\w+?(?:\.?\w+?)*?(?=\s|\]))(.+)*?\s*?\]#i';
$pattern = '#\[\s*(\w+(?:\.?\w+)*(?=\s|\]))(.+)\s*\]#i';

$content = preg_replace_callback( $pattern, function( $matches ) {
    // Do things with the matches
}, $content );

// Send content back to the template
return $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-06-11T15:30:59+00:00Added an answer on June 11, 2026 at 3:30 pm

    It turns out the regex was the culprit. It was pulling in the content beyond the tag on the same line on some cases, but this pattern solved the problem – #\[\s*(\w[^\]\s]*)(.*?)\s*\]#i.

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

Sidebar

Related Questions

Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Here is the code I'm using http://jsbin.com/evike5/edit When the jQuery UI dialog is fired
Here's the setup - I have a view that lists products. On that same
Here is a scenario: User installs .NET application that you have made. After some
Here's a sample of a SpinBox that writes its changes to underlying variables. The
Here is my scenario. I have a website running under AppPool1 and that works
Here's the code I have. It works. The only problem is that the first
Here's the two scenarios. We are using a manually built xml soap request with
Here's the scenario: I have a local git repository that mirrors the contents of

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.