If you only need to know the number of characters that are in the variable, you can simply use strlen($field), so your code would be
while ( $a_row = mysql_fetch_row( $result) )
{
echo "<tr>\n";
foreach ( $a_row as $field )
if ( strlen($field) == 4)
{
do this
}
else
{
echo "\t<td>$field</td>\n";
echo "</tr>\n";
}
Otherwise, if you want to know if it's a "chain" of characters, like let's say you want to find "mouse" - a 5 character word - in "the mouse is cool", you could do something with preg_match:
while ( $a_row = mysql_fetch_row( $result) )
{
echo "<tr>\n";
foreach ( $a_row as $field )
if (preg_match("/.*[a-zA-Z]{4}[^a-zA-Z].*/", $field))
{
do this
}
else
{
echo "\t<td>$field</td>\n";
echo "</tr>\n";
}
The pregmatch says "look until you find exactly 4 characters (from a-z, small or capital), followed by something not a character"
Hope that helps 😃