好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php代码中如何输出数学公式

使用google的接口显示数学公式

单行公式 (推荐学习:PHP视频教程)

<img src="http://latex.codecogs.com/gif.latex?$(a_{1})^2+(a_{3})^2\geq%202(a_{2})^2$" /> 

多行公式

<img src="http://latex.codecogs.com/gif.latex?$$%20\left\{%20\begin{aligned}%200\leq%20x\leq%202%20\\%200\leq%20y\leq%202\\%20\end{aligned}%20\right.%20$$" /> 

$str='$$ \left\{
    \begin{aligned}
    x^2+3y^2=3 \\
    y=k(x-1)\\
    \end{aligned}
    \right.
   $$';
    //将$$转化为$$
    $str=str_replace("$$", "$", $str);
    // dd($str);
    $pattern='/\$(.*)\$/Us';//只能识别$$  $$
    preg_match_all($pattern,$str,$matches);
    $arr_split=preg_split($pattern,$str);
    //dd($arr_split);
    // dd($matches);
    $count=count($matches[1]);
    $str_new="";
    for($i=0;$i<count($matches[1]);$i++){
   //$arr_replace[]='<img src="http://latex.codecogs.com/gif.latex?'.$matches[1][$i].'" />';
   $matches_str=$matches[1][$i];
   // dd($str);
   //先把\\n转换成\\\n
   $matches_str=str_replace("\\\n", "\\\\\n", $matches_str);
   // dd($matches_str);
   $matches_str=preg_replace('/\s*/', '', $matches_str);
   // dd($matches_str);
   $str_new.=$arr_split[$i];
   $str_new.='<img src="http://latex.codecogs.com/gif.latex?'.$matches_str.'" />';
    }
    if($count>0){
   echo $str_new;
    }else{
   echo $str;
    } 

以上就是php代码中如何 输出数学公式的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于php代码中如何输出数学公式的详细内容...

  阅读:40次

上一篇: php主流框架有哪些?

下一篇:php不执行