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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:01:43+00:00 2026-05-11T01:01:43+00:00

Hey everyone, I’m working on a PHP application that needs to parse a .tpl

  • 0

Hey everyone, I’m working on a PHP application that needs to parse a .tpl file with HTML in it and I’m making it so that the HTML can have variables and basic if statements in it. An if statement look something like this: `

<!--if({VERSION} == 2)--> Hello World <!--endif --> 

To parse that, I’ve tried using preg_replace with no luck. The pattern that I tried was

/<!--if\(([^\]*)\)-->([^<]*)<!--endif-->/e

which gets replaced with

if($1) { echo '$2'; }

Any ideas as to why this won’t work and what I can do to get it up and running?

  • 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. 2026-05-11T01:01:43+00:00Added an answer on May 11, 2026 at 1:01 am

    I think you meant to do this:

    '/<!--if\(([^)]*)\)-->([^<]*)<!--endif-->/' 

    Your regex has only one character class in it:

    [^\]*)\)-->([^<] 

    Here’s what’s happening:

    • The first closing square bracket is escaped by the backslash, so it’s matched literally.
    • The parentheses that were supposed close the first capturing group and open the second one are also taken literally; it isn’t necessary to escape parens inside a character class.
    • The first hyphen is taken as a metacharacter; it forms the range [)*+,-]
    • The second opening square bracket is taken as a literal square bracket because it’s inside a character class.
    • The second caret is taken as a literal caret because it’s not the first character in the class.

    So, after removing the duplicates and sorting the characters into their ASCII order, your character class is equivalent to this:

    [^()*+,\-<>\[\]^] 

    And the parentheses outside the character class are still balanced, so the regex compiles, but it doesn’t even come close to matching what you wanted it to.

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

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Nope it's not possible, for the browser to execute any… May 11, 2026 at 3:06 pm
  • added an answer I think what you're looking for is sed... it's a… May 11, 2026 at 3:06 pm
  • added an answer Here is one algorithm which should accomplish the task. The… May 11, 2026 at 3:06 pm

Related Questions

Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey everyone, I am trying to run the following program, but am getting a
Hey everyone. I'm trying to make a swing GUI with a button and a
Hey everyone, I'm working on a PHP application that needs to parse a .tpl
I need to calculate the DateDiff (hours) between two dates, but only during business-hours

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.