|
|
Posted by Rik Wasmus on 10/30/07 00:52
On Tue, 30 Oct 2007 01:29:11 +0100, David Williams =
<dw149@acmex.gatech.edu> wrote:
> Rik Wasmus <luiheidsgoeroe@hotmail.com> wrote:
> Thank you so much Rik.
Thank me by not topposting, fixed :).
>> On Tue, 30 Oct 2007 00:50:33 +0100, David Williams
>> <dw149@acmex.gatech.edu> wrote:
>> > Can anyone see why the javascript var abc here is not getting assig=
ned
>> > the php var ("Hello")? in my code? I have tried a lot of differen=
t =
>> ways
>> > but the javascript variable will not take.
>> > <script>
>> > var abc
>> > <?php
>> > $sizeof_image_array=3D5;
>> > for($i=3D0;$i<$sizeof_image_array;$i++)
>> > {
>> >
>> > $temp_image_name=3D"Hello";
>> > echo 'abc=3D<?php echo $temp_image_name;?>;';
>
>> Well, look at your source. What's the output here? And even if it wou=
ld
>> work, why would you keep overwriting the abc variable? (BTW: allthoug=
h =
>> not
>> required, it's a good idea to finish javascript lines with ';'.)
>
>> echo "abc=3D'".addslashes($temp_image_name)."';";
>
>> Keep in mind PHP does _NOT_ communicate with javascript. It will outp=
ut
>> something that could be valid javascript, but doesn't care wether it'=
s
>> javascript, the latest budget report or some very deep poetry.
> Now, to the code:
>
>
> echo "abc=3D'".addslashes($temp_image_name)."';";
>
> echo " blah "; // the code in its most simplest form
Euhm, what?
> which outputed will be a Java statement
Java? I thought you said javascript? And wether or not it is, to PHP it'=
s =
'just another string'.
> echo "abc=3D <blah>"; // if php does not talk to JS, how does
> php know what abc is ?
PHP doesn't. You happen create javascript code with PHP, but PHP doesn't=
=
know that. It's just another string for PHP. You might as well do an ech=
o =
"Do not go gentle into that good night.\nRage, rage against the dying of=
=
the light.", PHP won't treat it any differently
> The addslashes I suppose is to escape the double quotes around
> the "Hello"?
In this case, there are no quotes aroung "Hello". There could be, if you=
=
had defined it like: $temp_image_name=3D'"Hello"';
> Why?
Because your javascript could break if there are quotes in your string.
> And the periods?
Oh my... RTFM: normal PHP concatination.
-- =
Rik Wasmus
[Back to original message]
|