PDA

View Full Version : escaping math operators?


killa seven
02-08-2010, 09:01 PM
$totalscore = $cvote - $ovote;
ok this was the first attempt, i know that for integers you don't put double quotes around them but if you don't it acts as a integer and does any math...

$totalscore = "$cvote - $ovote";
i made the totalscore into a string, i thought maybe it would do this without doing any math

say the score is 5-2 i don't want this to do the math and subtract 2 from 5

i want it to display as 5-2

kh99
02-08-2010, 09:18 PM
When I try this php script:

<?php

$cvote = 5;
$ovote = 2;

$totalscore = "$cvote - $ovote";

echo $totalscore;

?>

I get:

5 - 2

as the output. But if it's not working for you, you could try

$totalscore = $cvote. ' - '.$ovote;

killa seven
02-09-2010, 12:10 AM
$totalscore = $cvote. ' - '.$ovote;

this should work i dont like using echo

kh99
02-09-2010, 03:04 AM
Well yeah, you probably don't want to use echo, that was just a test program to show that "$cvote - $ovote" doesn't do the subtraction. I don't understand why the other option should be any different, but whatever, as long as your problem is solved.

killa seven
02-10-2010, 02:04 AM
it seems like echo always puts the output at the very top of the page in the hook location... in the end you would want to put the variable inside of the template...

i can't echo $totalscore out because $totalscore is being inserted into the database...

im making a mod that shows the results of your polls in your sig....

and i need an actual score display instead of it doing math (5-2)

this didn't work btw it still does the math

kh99
02-10-2010, 09:34 AM
Yeah, what I posted was just a "stand alone" php program, in vBulletin you usually don't want to use echo because vBulletin works by collecting up the output in a string then echoing it at the end, so if you call echo before that, whatever you echo will come out first. But the echo doesn't have anything to do with how the expression is evaluated, I just used it to output a string in the test program.

I guess maybe your problem is because the result of your string concatenation is an expression that is being eval'd later. I don't know how to fix it without understanding more of what's going on. Maybe someone else does.