function VbsString($str, $default = '') { if (empty($str)) { $str = $default; if (empty($str)) { return '""'; } } settype($str, 'string'); $out = ''; $inStr = false; $len = mb_strlen($str); // Allow: a-z A-Z 0-9 SPACE , . // Allow (dec): 97-122 65-90 48-57 32 44 46 for ($cnt = 0; $cnt < $len; $cnt++) { $c = Reform::uniord(Reform::unicharat($str, $cnt)); if ($c >= 97 && $c <= 122 || $c >= 65 && $c <= 90 || $c >= 48 && $c <= 57 || $c == 32 || $c == 44 || $c == 46) { if (!$inStr) { $inStr = true; $out .= '&"'; } $out .= Reform::unicharat($str, $cnt); } else { if (!$inStr) { $out .= sprintf('&chrw(%d)', $c); } else { $out .= sprintf('"&chrw(%d)', $c); $inStr = false; } } } return ltrim($out, '&') . ($inStr ? '"' : ''); }