function WF_filter_math($text, $editor) { global $TAGS; $output = ''; $n0 = 0; // Search for '«math'. If it is not found, the // content is returned without any modification $n1 = strpos($text, $TAGS->in_mathopen); if ($n1 === FALSE) { return $text; // directly return the content } // filtering while ($n1 !== FALSE) { $output .= substr($text, $n0, $n1 - $n0); $n0 = $n1; $n1 = strpos($text, $TAGS->in_mathclose, $n0); if (!$n1) { break; } $n1 = $n1 + strlen($TAGS->in_mathclose); // Getting the substring «math ... «/math» $sub = substr($text, $n0, $n1 - $n0); // remove html entities (such as ") //Solves BUG 25670 of php 4.3, solved at version 5 if (version_compare(phpversion(), "5.0.0", ">=")) { $sub = html_entity_decode($sub, ENT_COMPAT, $TAGS->ucharset); // needs php 4.3 to work, php 5.0 if charset is utf (bug 25670) } else { if (strtolower($TAGS->ucharset) == "utf-8") { $sub = html_entity_decode_utf8($sub); } else { $sub = html_entity_decode($sub, ENT_COMPAT, $TAGS->ucharset); } } // replacing '«' by '<' $sub = str_replace($TAGS->in_open, $TAGS->out_open, $sub); // replacing '»' by '>' $sub = str_replace($TAGS->in_close, $TAGS->out_close, $sub); // replacing '§' by '&' $sub = str_replace($TAGS->in_entity, $TAGS->out_entity, $sub); // generate the image code $sub = WF_math_image($sub, $editor); // appending the modified substring $output .= $sub; $n0 = $n1; // searching next '«math' $n1 = strpos($text, $TAGS->in_mathopen, $n0); } $output .= substr($text, $n0); return $output; }
<?php require_once '../../config.php'; require_once './math_filter.php'; global $TAGS; global $CFG; $var = $_POST["var"]; //We can not do urldecode because it will transform '+' simbols //$var=urldecode($var); WF_initmathfilter(); //require_once($CFG->libdir . '/textlib.class.php'); //$convertor = textlib_get_instance(); //$var = $convertor->convert($var,'utf-8',$TAGS->lcharset); //transforms the mathml to a html image //$var = WF_filter_math($var,TRUE); $var = WF_math_image($var, TRUE); echo $var;