N
N
Ninazu2015-12-16 16:12:22
PHP
Ninazu, 2015-12-16 16:12:22

How to cut all blocks that do not contain an attribute?

The piece being tested

$test = '<input type="hidden" name="submitted" value="TRUE" />
      <!-- LOCALE uk -->
      <h2 class="">Required Information UK</h2>
      <!-- /LOCALE -->
<!-- LOCALE uk --><h2 class="">Required Information UK</h2><!-- /LOCALE -->
<!-- LOCALE ru -->
<h2 class="">Required Information RU</h2>
<!-- /LOCALE -->

<!-- LOCALE -->
<h2 class="">Required Information EMPTY</h2>
<!-- /LOCALE -->
<div class="content_indent" style="width: 764px; margin-bottom: 35px;">';


//Попытки :(
echo preg_replace('#<!--\s+LOCALE\s+(ru)\s+-->.*?<!--\s+/LOCALE\s+-->#sm','',$test);

It is necessary to cut out all blocks in which LOCALE does not have the ru attribute. While it turned out to cut out only everything with this attribute. How to specify inversion? (?!ru) - it won't start like that

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
heartdevil, 2015-12-16
@Ninazu

Hello.
Here's a regex try slip. UPDATE
Example : Example 2

R
Robot, 2015-12-16
@iam_not_a_robot

Isn't it easier to remove all blocks with ru preg_replace like this https://regex101.com/r/dX2wH3/1 and that 's it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question