<p>Craft’s <a href="https://craftcms.com/docs/4.x/searching.html" rel="nofollow noreferrer">search system</a> indexes and matches against normalized keywords, not exact text. HTML in particular has all its special characters stripped out, so something like <code>&lt;span class=&quot;busted&gt;markup&lt;/span&gt;</code> would end up being indexed as <code>span class busted markup span</code>! Your search query is <em>also</em> normalized, though, so a query for <code>&lt;span</code> <em>should</em> match at least the <code>span</code> keyword…</p>
<p>If you know which fields contain the bad code, you can use the condition builder to query against actual field data. Alternatively, building the query in a template will give you precise control over the input:</p>
<pre><code>{% set badEntries = craft.entries()
  .myFieldWithPotentiallyMalformedHtml('*&lt;span*')
  .all() %}
</code></pre>
<p>This will return an entry that has <code>&lt;span class=&quot;busted&gt;markup&lt;/span&gt;</code> in it.</p>
<hr />
<p>Keep in mind that this is only doing simple string matching in the database—if you need to scan for in/valid HTML or specific HTML attributes, you may need to perform more advanced matching with PHP… perhaps by loading <em>all</em> potentially-affected entries, then scanning the field values with regular expressions, HTMLPurifier, or other techniques!</p>

CC BY-SA 4.0
2023-05-17T20:38:31.723Z
Thank you so much!
Document Services
CC BY-SA 4.0
2023-05-17T20:10:00.873Z
2023-05-17T20:10:00.873Z
August Miller
<p>I'm trying to use the Admin interface to search entries with specific types of HTML code entered incorrectly by a client. What is the best way to do this?</p>
<p>Searching for the html itself &quot;&lt;span&quot; doesn't not yield correct results. The field with this text in is it search indexed.</p>
<p>Thank you so much!</p>

<admin>
Search Entries for HTML Code
# Search Entries for HTML Code

(Asked by: username_0 on 2023-05-17)

I'm trying to use the Admin interface to search entries with specific types of HTML code entered incorrectly by a client. What is the best way to do this?

Searching for the html itself "

Thank you so much!

**Tags:** admin

---

## 1 answers

### Answer by username_1 on 2023-05-17. Score: 1

Craft’s [search system](https://craftcms.com/docs/4.x/searching.html) indexes and matches against normalized keywords, not exact text. HTML in particular has all its special characters stripped out, so something like `markup` in it.

---

Keep in mind that this is only doing simple string matching in the database—if you need to scan for in/valid HTML or specific HTML attributes, you may need to perform more advanced matching with PHP… perhaps by loading *all* potentially-affected entries, then scanning the field values with regular expressions, HTMLPurifier, or other techniques!

> **Comments:**
> **username_0**: Thank you so much!  

---

