如何在php代碼中輸出數(shù)學公式?針對這個問題,今天小編總結這篇代碼文字解析結合的文章,希望幫助更多同學解決這個問題。
使用google的接口顯示數(shù)學公式
單行公式
多行公式
$str='$$ \left\{ \begin{aligned} x^2+3y^2=3 \\ y=k(x-1)\\ \end{aligned} \right. $$'; //將$$轉(zhuǎn)化為$$ $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'; $matches_str=$matches[1][$i]; // dd($str); //先把\\n轉(zhuǎ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.=' '; } if($count>0){ echo $str_new; }else{ echo $str; }
看完上訴內(nèi)容,你們掌握在php代碼中輸出數(shù)學公式的方法了嗎?如果想了解更多相關內(nèi)容,歡迎關注創(chuàng)新互聯(lián)成都網(wǎng)站設計公司行業(yè)資訊頻道,感謝各位的閱讀!
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。