text) as $line) { $len = mb_strlen($line, "UTF-8"); mb_ereg_search_init($line, "\w+"); while (($wpos = mb_ereg_search_pos()) != FALSE) { $word = mb_substr($line, $wpos[0], $wpos[1]); if (!pspell_check($spell, $word)) { $woffset = mb_strlen(mb_substr($line, 0, $wpos[0]), "UTF-8"); $wlen = mb_strlen($word, "UTF-8"); array_push($suggestions, array($offset + $woffset, $wlen, pspell_suggest($spell, $word))); } } $offset += $len + 1; } $xml = new SimpleXMLElement(""); $xml->addAttribute("error", count($suggestions) ? "1" : "0"); foreach ($suggestions as $s) { $c = $xml->addChild("c", join("\t", $s[2])); $c->addAttribute("o", $s[0]); $c->addAttribute("l", $s[1]); $c->addAttribute("s", "1"); } header('Content-Type: text/xml'); echo $xml->asXML();