Home > Backend Development > PHP Problem > How to output mathematical formulas in php code

How to output mathematical formulas in php code

(*-*)浩
Release: 2023-02-27 08:38:02
Original
3345 people have browsed it

How to output mathematical formulas in php code

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

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

<img  src="http://latex.codecogs.com/gif.latex?$(a_{1})^2+(a_{3})^2\geq%202(a_{2})^2$" / alt="How to output mathematical formulas in php code" >
Copy after login

How to output mathematical formulas in php code

多行公式

<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$$" / alt="How to output mathematical formulas in php code" >
Copy after login

How to output mathematical formulas in php code

How to output mathematical formulas in php code

$str=&#39;$$ \left\{
                   \begin{aligned}
                   x^2+3y^2=3 \\
                   y=k(x-1)\\
                   \end{aligned}
                   \right.
        $$&#39;;
    //将$$转化为$$
    $str=str_replace("$$", "$", $str);
    // dd($str);
    $pattern=&#39;/\$(.*)\$/Us&#39;;//只能识别$$  $$
    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[]=&#39;<img  src="http://latex.codecogs.com/gif.latex?&#39;.$matches[1][$i].&#39;" / alt="How to output mathematical formulas in php code" >&#39;;
        $matches_str=$matches[1][$i];
        // dd($str);
        //先把\\n转换成\\\n
        $matches_str=str_replace("\\\n", "\\\\\n", $matches_str);
        // dd($matches_str);
        $matches_str=preg_replace(&#39;/\s*/&#39;, &#39;&#39;, $matches_str);
        // dd($matches_str);
        $str_new.=$arr_split[$i];
        $str_new.=&#39;<img  src="http://latex.codecogs.com/gif.latex?&#39;.$matches_str.&#39;" / alt="How to output mathematical formulas in php code" >&#39;;
    }
    if($count>0){
        echo $str_new;
    }else{
        echo $str;
    }
Copy after login

How to output mathematical formulas in php code

How to output mathematical formulas in php code

The above is the detailed content of How to output mathematical formulas in php code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template