Is $file\n a string variable? Why does it echo ok but mess up my fuction?

This is a discussion on Is $file\n a string variable? Why does it echo ok but mess up my fuction? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I have a block of code that opens a directory and creats a file list with a small button image ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-02-2004
Rich Zellmer
 
Posts: n/a
Default Is $file\n a string variable? Why does it echo ok but mess up my fuction?

I have a block of code that opens a directory and creats a file list with a
small button image next to each name. Above this list is a blank form, with
some text boxes. My plan is to add some Javascript so that I can drag the
button to my form and have a text box populate with the file name from the
button I just dragged each file so that I can drag the image next to each
file name in to a form text box and have

I can echo "$file\n" to get the file name to appear in its spot in the list.
however when I try and use $file\n inside the function
event.dataTransfer.setData("TEXT",'$file\n') I get an undertermined string
constant error.

It only takes a slight change to the code to get it to work which makes me
think the probem is with the $file\n

If I change the event.dataTransfer.setData to
event.dataTransfer.setData("TEXT",'dog')
everything works fine and I get dog in the box if I drag the image.


I thought maybe I could not use a variable inside this fuction however if I
put
event.dataTransfer.setData("TEXT",'$Z')
I get the value of the $Z loop counter

Do I need to convert $file\n to a string first? If so how can I do this.
My code is below. Otherwise what is differnt about $file\n then my $Z
counter that I cant pass it to the even.dataTranfer.setData function?

Rich


<?php
// This block is the file browse code
if ($handle = opendir('../docs/')) {

/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
$Z=$Z+1;

echo "$file\n <IMAGE ID='a$Z' SRC='button.gif'
ondragstart='a$Z()'>
$Z<BR>

<SCRIPT>
function a$Z()
/* The setData parameters tell the source object
to transfer data as a URL and provide the path. */
{
event.dataTransfer.setData('TEXT', '$file\n' );
}
</SCRIPT>
";
}


/* This is the WRONG way to loop over the directory. */
while ($file = readdir($handle)) {
echo "$file\n";

}
closedir($handle);
}
?>


Reply With Quote
  #2 (permalink)  
Old 02-02-2004
Tyrone Slothrop
 
Posts: n/a
Default Re: Is $file\n a string variable? Why does it echo ok but mess up my fuction?

On Sun, 1 Feb 2004 22:28:50 -0500, "Rich Zellmer"
<tdmailbox@yahoo.com> wrote:

>I can echo "$file\n" to get the file name to appear in its spot in the list.
>however when I try and use $file\n inside the function
>event.dataTransfer.setData("TEXT",'$file\n') I get an undertermined string
>constant error.


Try: "$file\n"
Single and double quotes are evaluated differently.
Or: $file."\n"


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:20 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0