# Strip HTML comments from markdown content

**URL:** <https://forum.getkirby.com/t/strip-html-comments-from-markdown-content/10724>\
**Category:** Solutions\
**Tags:** v2\
**Created:** [July 2, 2018, 2:38pm UTC](https://forum.getkirby.com/t/strip-html-comments-from-markdown-content/10724 "2018-07-02T14:38:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [July 2, 2018, 2:38pm UTC](https://forum.getkirby.com/t/strip-html-comments-from-markdown-content/10724/1 "2018-07-02T14:38:19Z")

</div>

We can add HTML comments `<!-- Hello world! -->` into markdown and it’s nice when we have copied something useful from the web that we want to base a page on. However, the comment it will be published as well, because it’s HTML, not PHP.

So I made a super small post filter to strip out HTML comments from the markdown content.

**Regex source:** [Remove HTML Comments with PHP](https://davidwalsh.name/remove-html-comments-php)

```php
<?php
kirbytext::$post[] = function($kirbytext, $value) {
    return preg_replace('/<!--(.|\s)*?-->/', '', $value);
};

```

Then it will magically remove all HTML comments from all content when using like `$page->text()->kt()`.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:27pm UTC](https://forum.getkirby.com/t/strip-html-comments-from-markdown-content/10724/2 "2025-02-06T17:27:50Z")

</div>


