1, '"//' => 1, '\'//' => 1, '".//' => 2, '\'.//' => 2, ); break; case '/*': $fakes = array( '"/*' => 1, '\'/*' => 1, '"//*' => 2, '\'//*' => 2, '".//*' => 3, '\'.//*' => 3, '*/*' => 1, '\\/*' => 1, ); break; default: $fakes = array(); } $index = strpos($str, $token); $offset = 0; while ($index !== false) { foreach ($fakes as $fake => $skip) { $check = substr($str, $index - $skip, strlen($fake)); if ($check === $fake) { // move offset and scan again $offset += $index + strlen($token); $index = strpos($str, $token, $offset); break; } } // legitimate find return $index; } return $index; } }