Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/256205-how-to-display-math-equation/
Share on other sites

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

 


$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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.