I have a String, let's say:
$needle = "HELLO";
$haystack = "HELLO WORLD";
I've interpreted your question as:
I want to find a string within another string, making the matching characters a different colour in the output
Easiest method would be
<style>.myclass { color: red; }</style>
<?php
$needle = "HELLO";
$haystack = "HELLO WORLD";
$myOutput = str_replace($needle,"<a class='myclass'>".$needle."</a>",$haystack);
echo $myOutput;
?>
Obviously editing it to suit the method you're intending for it, but the above should help with one possible solution.