Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-17T20:38:31.723Z
Answers.Text: Thank you so much!
Answers.UserDisplayName: Document Services
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-17T20:10:00.873Z
Answers.LastActivityDate: 2023-05-17T20:10:00.873Z
Answers.UserDisplayName: August Miller
Body: <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>
  
Tags: <admin>
Title: Search Entries for HTML Code
ThreadText: # 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 "<span" doesn't not yield correct results. The field with this text in is it search indexed.
  
  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 `<span class="busted>markup</span>` would end up being indexed as `span class busted markup span`! Your search query is *also* normalized, though, so a query for `<span` *should* match at least the `span` keyword…
  
  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:
  
  ```
  {% set badEntries = craft.entries()
    .myFieldWithPotentiallyMalformedHtml('*<span*')
    .all() %}
  
  ```
  
  This will return an entry that has `<span class="busted>markup</span>` 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!  
  
  ---
  
  