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

发布时间:2020-05-11 17:56:59 作者:Leah
来源:亿速云 阅读:458

如何在php代码中输出数学公式?针对这个问题,今天小编总结这篇代码文字解析结合的文章,希望帮助更多同学解决这个问题。     

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

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

单行公式  

<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$$" />

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

$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代码中输出数学公式的方法了吗?如果想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. 如何在HTML5中使用MathML数学公式
  2. 如何在python输出数据中的奇数

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php 代码输出数学公式

上一篇:crs自动清除日志的时候没有释放文件,bug17034444 的解决办法

下一篇:MySQL数据库优化

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》