P3t3r Posted March 16, 2008 Share Posted March 16, 2008 This is the script that I execute on the text. // LaTeX formula rendering unset($tex_matches); // for $...$ preg_match_all("#\\\$(.*?)\\\$#si",$text,$tex_matches); for ($i=0; $i < count($tex_matches[0]); $i++) { $pos = strpos($text, $tex_matches[0][$i]); $formula = html_entity_decode($tex_matches[1][$i]); $formula = preg_replace("#\\\$(.*?)\\\$#si", "\\\$\\1\\\$", $formula); $formula = str_replace(':',':',$formula); $alt_formula = htmlentities($formula, ENT_QUOTES); $alt_formula = str_replace("\r","",$alt_formula); $alt_formula = str_replace("\n","\\\\",$alt_formula); $text = substr_replace($text, "<p><img src='my_site_here/mathtex.cgi?".$alt_formula."' title='".$alt_formula."' alt='".$alt_formula."'></p>",$pos,strlen($tex_matches[0][$i])); } What the script should do: replacing text between dollars with an image. Like Hello, this is the $4^{th}$ time I get a $404$ error. should be replaced with Hello, this is the <img src="site/img?4^{th}"> time I get a <img src="site/img?404"> error. But somehow it doesn't work. Can anyone help me? Quote Link to comment https://forums.phpfreaks.com/topic/96391-text-replace-script-why-is-it-not-working/ Share on other sites More sharing options...
P3t3r Posted March 16, 2008 Author Share Posted March 16, 2008 Does anyone see what I do wrong? Quote Link to comment https://forums.phpfreaks.com/topic/96391-text-replace-script-why-is-it-not-working/#findComment-493488 Share on other sites More sharing options...
BlueSkyIS Posted March 16, 2008 Share Posted March 16, 2008 what's not working? can you echo to see if there are any matches? i would add echo's through the code, debug to see what the values are after each step. echo count($tex_matches[0]); Quote Link to comment https://forums.phpfreaks.com/topic/96391-text-replace-script-why-is-it-not-working/#findComment-493491 Share on other sites More sharing options...
sasa Posted March 16, 2008 Share Posted March 16, 2008 try <?php $text = 'Hello, this is the $4^{th}$ time I get a $404$ error.'; echo $t = preg_replace('/\$(.*?)\$/','<img src="site/img?$1">',$text); ?> Quote Link to comment https://forums.phpfreaks.com/topic/96391-text-replace-script-why-is-it-not-working/#findComment-493502 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.