0

Im working on php-html-js templating shell, and i want to callback class, via ajax, as part of template html.

The view of html is something like that:

<center>this is main part</center>
<button class="btns"> class buttons </button>
<div> also main </div>
<!--[part:AJAX]-->
<div> BUT This part at first should be removed with comments, and all inside <!--[part:ANYVAR]--> till
the same comment: </div>
<!--[part:AJAX]-->

But after i need to do an oposite thing : remove all except for inside

Ps thank's for you attention :)

6

1 Answer 1

1

This regular expression will find the comments and what's inside:

$pattern = "/(<!--\[part:AJAX\]-->.*<!--\[part:AJAX\]-->)/ms";
preg_match($pattern, $html, $matches);
echo $matches[1];

To remove between comments, change your pattern to:

$pattern = "/(<!--\[part:AJAX\]-->(.*)<!--\[part:AJAX\]-->)/ms";

Then

echo str_replace($matches[2], "", $html);
Sign up to request clarification or add additional context in comments.

1 Comment

Cool! Would be the great if you show me how to remove all between comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.