Latex preg_替换更改括号和文本

Latex preg_替换更改括号和文本,latex,brackets,preg-replace-callback,Latex,Brackets,Preg Replace Callback,我有一个PHP文本字符串: $str = 'This is a simple \^{text}. It does not look well \_{styled}.'; 我想做的是使用preg\u replace更改\^{text}和{styled}以获得如下html代码 $str = 'This is a simple <sup>text<sup>. It does not look well <sub>styled</sub>.'; 我现在

我有一个PHP文本字符串:

$str = 'This is a simple \^{text}. It does not look well \_{styled}.';
我想做的是使用preg\u replace更改\^{text}和{styled}以获得如下html代码

$str = 'This is a simple <sup>text<sup>. It does not look well <sub>styled</sub>.';
我现在所做的是:

function Translate($str)
{
   return preg_replace('/\\\\\^\{.*\}/i', '<sup>$1</sup>', $str);
}
echo Translate("this offer starts at \^{abc}");
这在1美元的情况下不能正常工作!在$0中,整个匹配是正确的。。。
有人能帮我吗?富豪们

Solution:Quick and dirty:$str='这是一个简单的\^{text}。它看起来不太好;echo preg_替换“~\\^{.?}”、“$2”、$str;echo preg_替换“~\\\{.?}~”、“$2”、$str;也许有人有更好的解决办法