<p>I want to discard all remaining characters in a string as soon as one of several unwanted characters is encountered.</p>
<p>As soon as a blacklisted character is encountered, the string before that point should be returned.</p>
<p>For instance, if I have an array:</p>
<pre><code>$chars = array(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;);
</code></pre>
<p>How would I go through the following string...</p>
<pre><code>log dog hat bat
</code></pre>
<p>...and end up with:</p>
<pre><code>log dog h
</code></pre>

The
strcspn
function is what you are looking for.
```
```
<?php

$mask = "abc";

$string = "log dog hat bat";

$result = substr($string,0,strcspn($string,$mask));

var_dump($result);

?>
```
```