… -- => – --- => — "" => „“ >> => » << => « (C) => © (R) => ® (TM)=> ™ v $ => v $ (for A, I, i, K, k, S, s, V, v, O, o, U, u, Z, z) It will not do any replaces between '<' and '>' characters and inside PRE and CODE containers. Usage: $result = czechtypo($text); Copyright (c) 2007 Radek Brich (radek at brich.org) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ $czechtypo_version = '2.0'; // checks for white-space characters function czechtypo_isspace($c) { return ($c == ' ' || $c == '\n' || $c == '\r' || $c == '\t'); } // checks for alphanumeric characters function czechtypo_isalnum($c) { return (($c >= 'A' && $c <= 'Z') || ($c >= 'a' && $c <= 'z') || ($c >= '0' && $c <= '9') || $c == '_' || ord($c) >= 128); } // read a token -- a HTML tag, continuous dashes or dots, // or just one char function czechtypo_readtoken($text, &$i) { $state = 0; $output = ''; while ($state < 20 && $i < strlen($text)) { $c = $text[$i++]; switch ($state) { // start case 0: if ($c == '<') $state = 1; else if ($c == '>') $state = 3; else if ($c == '-') $state = 4; else if ($c == '.') $state = 5; else if ($c == '(') $state = 6; else if (czechtypo_isspace($c)) $state = 9; else if (czechtypo_isalnum($c)) $state = 10; else $state = 20; break; // < case 1: if ($c == '<' || $c == '>') $state = 20; else $state = 2; break; // tag case 2: if ($c == '>') $state = 20; break; // > case 3: if ($c == '>') $state = 20; else $state = 21; break; // dashes case 4: if ($c != '-') $state = 21; break; // dots case 5: if ($c != '.') $state = 21; break; // left parentesis case 6: if ($c == 'T') $state = 7; else if ($c == 'C' || $c == 'R') $state = 8; else $state = 21; break; // (T case 7: if ($c == 'M') $state = 8; else $state = 21; break; // (C, (R, (TM case 8: if ($c == ')') $state = 20; else $state = 21; break; // spaces case 9: if (!czechtypo_isspace($c)) $state = 21; break; // a word case 10: if (!czechtypo_isalnum($c)) $state = 21; break; } if ($state == 21) $i--; else $output .= $c; } return $output; } // main function function czechtypo($text) { $state = 0; $quot = 0; $i = 0; $output = ''; while (($token = czechtypo_readtoken($text, $i)) != '') { switch ($state) { // start case 0: // after one letter long preposition case 1: if (!strcmp($token, '--')) $output .= '–'; else if (!strcmp($token, '---')) $output .= '—'; else if (!strcmp($token, '...')) $output .= '…'; else if (!strcmp($token, '(C)')) $output .= '©'; else if (!strcmp($token, '(R)')) $output .= '®'; else if (!strcmp($token, '(TM)')) $output .= '™'; else if (!strcmp($token, '>>')) $output .= '»'; else if (!strcmp($token, '<<')) $output .= '«'; else if ($token == '"') { if ($quot) $output .= '“'; else $output .= '„'; $quot = !$quot; } else if ($state == 1) { if ($token == ' ') $output .= ' '; else $output .= $token; $state = 0; } else $output .= $token; if (strlen($token) == 1 && strstr('AIiKkSsVvOoUuZz', $token)) $state = 1; else if (stristr($token, '