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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:27:39+00:00 2026-06-14T16:27:39+00:00

I found that php preg_replace doesn’t work with HTML tag. Let’s say I have

  • 0

I found that php preg_replace doesn’t work with HTML tag.

Let’s say I have such a code:

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

$this->cms_language() will return one of “english”, “german” or “indonesia”

When I assign such a string to $value, it will give either “Victoria”, “Hitler” or “Sule” depend on the $language’s value:

$value = '{{ if_language:english }}Victoria{{ elif_language:german }}Hitler{{ else }}Sule{{ end_if }}</p>'

But it won’t work when I change $value into

$value = '{{ if_language:english }}<br />
Victoria<br />
{{ elif_language:german }}<br />
Hitler<br />
{{ else }}<br />
Sule<br />
{{ end_if }}</p>'

The will give $value itself as the output.

So what’s wrong here?

EDIT : Sorry I found this one works:

$value = '{{ if_language:english }}<br />Victoria<br />{{ elif_language:german }}<br /> Hitler<br />{{ else }}<br />Sule<br />{{ end_if }}';

So I guess the problem is with new line character, not with the <br /> tag

  • 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-14T16:27:40+00:00Added an answer on June 14, 2026 at 4:27 pm

    The problem is that you’re missing the right pattern modifier.

    In this case you should use the /s modifier, e.g.:

    /your pattern/s
    

    The /s modifier changes how dot . matches characters; by default it matches everything except newlines, but with /s it truly matches anything.

    Btw, you may want to also use /U modifier to make the expression (.*) non-greedy by default; greedy patterns will try to match as much as possible and you may get unexpected results if you use them.

    Multiple pattern modifiers are specified like this:

    /your pattern/sU
    

    Btw, instead of the /U modifier you can also use (.*?) to specify non-greedy matching.

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

Sidebar

Related Questions

I have found in sfDoctrineApplyPlugin a template called applyAfter.php that shows a message like
I have some PHP code that I'm using to send a form off to
I have this piece of code I found on some blog, that's supposed to
I once tried to implement Comet in PHP. Soon, I found that PHP is
I found that using Smarty with PHP, sometimes extra time will need to be
I was simply going through the tutorial of PHP there I found that we
I recently found an article online that told me about this: RewriteRule ^mock-up/([^/]+)/([^/]+) /mock-up/index.php?page=$1&section=$2
I found this interesting site, that helps me understand derivatives, http://www.numberempire.com/derivatives.php , It seems
I have found this link: http://www.jfree.org/forum/viewtopic.php?f=3&t=6314 Its back in 2007 where they agree that
I've found this code in base 64 on all php files of one 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.