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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:45:12+00:00 2026-06-14T17:45:12+00:00

I have a templating system to show things based on $this->cms_language() value. In this

  • 0

I have a templating system to show things based on $this->cms_language() value.
In this case, the $value will be replaced with something matched the regex pattern.
It works just as http://www.getnocms.com/2012/11/better-multi-language-template-better.html

    $language = $this->cms_language();
    $pattern = array();
    $pattern[] = "/\{\{ if_language:$language \}\}(.*?)\{\{ elif_language:.*?\{\{ end_if }}/s";
    $pattern[] = "/\{\{ if_language:$language \}\}(.*?)\{\{ else \}\}.*?\{\{ end_if }}/s";
    $pattern[] = "/\{\{ if_language:$language \}\}(.*?)\{\{ end_if }}/s";
    $pattern[] = "/\{\{ if_language:.*?\{\{ elif_language:$language \}\}(.*?)\{\{ elif_language:.*?\{\{ end_if }}/s";
    $pattern[] = "/\{\{ if_language:.*?\{\{ elif_language:$language \}\}(.*?)\{\{ else \}\}.*?\{\{ end_if }}/s";
    $pattern[] = "/\{\{ if_language:.*?\{\{ elif_language:$language \}\}(.*?)\{\{ end_if }}/s";
    $pattern[] = "/\{\{ if_language:.*?\{\{ else \}\}(.*?)\{\{ end_if }}/s"; 
    $replacement = '$1';
    $value = preg_replace($pattern, $replacement, $value);

So far everything was so good. But then, I noticed a problem. For example, I write a text area or an input that contains any of those pattern. Something like:

$value = '<input value="{{ if_language:indonesia }} do_something {{ end_if }}" />';

I don’t want the input value to be replaced even if it is match with the regex.
Since I’ve use a lot of patterns here, how is the most effective way to avoid this?

  • 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-14T17:45:13+00:00Added an answer on June 14, 2026 at 5:45 pm

    You may try to add

    foreach ($pattern as &$p) {
      $p = preg_replace("/^\//", "/(?![^<>]*>|(?:[^>]*<\/(?:[tT][eE][xX][tT][aA][rR][eE][aA]|[sS][eE][lL][eE][cC][tT])[^<>]*>))", $p);
    

    } }

    before your existing preg_replace to avoid this in most cases.

    See this demo.

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

Sidebar

Related Questions

I have borrowed code from this link PHP regex templating - find all occurrences
I have a templating system that looks similar to old-style ASP code. I run
I am working on templating system. I do have input of html document from
Say I need to have a templating system where a user can edit it
I'm struggling a bit with the play 2.0 templating system; I have a method
I have a templating system for a current project. I use str_replace() to replace
I have to work with an old templating system to display shopping products on
I am new to Handlebars templating system and this is my first project I
I have a quite old templating system written on top of ERB. It relies
Using the standard Django templating system, is there any snippet/reusable template tag to 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.