如何在php/HTML中显示数学方程式? [英] How to show math equation in php / HTML?

查看:87
本文介绍了如何在php/HTML中显示数学方程式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ckeditor,当我从数据库中提取方程式时,我们可以在其中创建数学方程式,它看起来像a+b2,但我想像(a+b)^2.那么,我该怎么做呢?请帮助我.

I have a ckeditor where we can create math equation when I am fetch equation from database it look like a+b2 but I want like (a+b)^2. So, How can I do this? Please help me.

html_entity_decode($post->answer)

我正在使用html_entity_decode,但看起来并不是我想要的.

I am using html_entity_decode but it not look exactly I want.

推荐答案

对MathML的浏览器支持仍然相当杂乱无章,但是您可以通过将MathJax库添加到Web文档中,使其在几乎所有浏览器中都能正常工作.只需将以下两行添加到您的HTML中:

Browser support for MathML is still rather patchy, but you can get it working in just about any browser by adding the MathJax library to your web document. Just add the following two lines to your HTML:

<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

然后应正确呈现.尝试运行以下代码段,例如:

It should then render correctly. Try running the following snippet for example:

<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<p>&nbsp;<math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><msup><mfenced><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow></mfenced><mn>2</mn></msup><mo>=</mo><msup><mi>a</mi><mn>2</mn></msup><mo>+</mo><msup><mi>b</mi><mn>2</mn></msup><mo>+</mo><mn>2</mn><mi>a</mi><mi>b</mi></mrow></math></p>

这篇关于如何在php/HTML中显示数学方程式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆