YigalB Posted February 1, 2012 Share Posted February 1, 2012 In order to display an equation of parabola, I copied from somewhere <span style="font-size: 200%"><span class="math"><b><var>y</var> = <var><?php echo "$a" ?></var><var>x</var><sup>2</sup> <?php echo "$sb"?> <var><?php echo "$b" ?></var><var>x</var> <?php echo "$sc"?> <var><?php echo "$c" ?></var></b></span></span> </p> <br> It doesn't look nice, and also it doesn't know how to eliminate parts when the parameter is zero. For example, in the case of y=ax^2+bx+c, and a=1 b=0 c=5, it would print y=1x^2+0x+5, instead of y=x^2+5 I could do pre-processing and solve it, but I was wondering if there is a nicer way to do that? Quote Link to comment https://forums.phpfreaks.com/topic/256205-how-to-display-math-equation/ Share on other sites More sharing options...
kicken Posted February 1, 2012 Share Posted February 1, 2012 There's not any way to have either php or the browser just automatically hide any part that would be zero, you have to manually figure out what does and does not need to be shown. As for making it look better you could look into using MathML Quote Link to comment https://forums.phpfreaks.com/topic/256205-how-to-display-math-equation/#findComment-1313489 Share on other sites More sharing options...
Andy-H Posted February 2, 2012 Share Posted February 2, 2012 $args[] = ($a ? '<var>'. $a .'</var>' : ''); $args[] = ($sb ? $sb : ''); $args[] = ($b ? '<var>'. $b .'</var>' : ''); $args[] = ($sc ? $sc : ''); $args[] = ($c ? '<var>'. $c .'</var>' : ''); $math = vsprintf('<span style="font-size: 200%"><span class="math"><b><var>y</var> = %s<var>x</var><sup>2</sup> %s %s <var>x</var> %s %s </b></span></span></p><br >', $args); Quote Link to comment https://forums.phpfreaks.com/topic/256205-how-to-display-math-equation/#findComment-1313513 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.