Jump to content

text replace script - why is it not working?


P3t3r

Recommended Posts

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(':','&#58;',$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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.