Forum Moderators: open

Message Too Old, No Replies

how do you make an integer a string?

         

marcus76

12:54 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



Ok, this is doing my head in now. I have the following.

$currency="£"

<script type="text/javascript">
<?php print("var euroRate = """ . $currency . """ ;\n");?>
</script>

I would expect this to display "£" not just £

any ideas?

Thanks

Rambo Tribble

1:11 pm on Aug 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd try escaping the quotes you wish to have appear in the string. You can also use the casting operator, (string), to assure that your variable is being converted, though that shouldn't be the problem.

marcus76

1:25 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



hey Rambo, thanks for your reply - i'm not so sure of the Escape syntax? would you mind posting an example?

thanks

coopster

3:39 pm on Aug 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Actually, you should be getting a PHP parse error. Escaping the string as described...
<?php 
$currency="£";
?>
<script type="text/javascript">
<?php print("var euroRate = \"" . $currency . "\" ;\n");?>
</script>

marcus76

8:33 am on Aug 20, 2004 (gmt 0)

10+ Year Member



coopster - you da man. worked a treat, thanks so much.

Marcus

dcrombie

12:05 pm on Aug 23, 2004 (gmt 0)



Short-hand:

<?= "var euroRate = \"$currency\";\n" ?>