Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax question 1

Status
Not open for further replies.

skibascott

IS-IT--Management
Mar 18, 2004
82
US
I am trying to use php to execute Javascript code. I need to open a new window with the url of a file on our intranet.
Code:
echo "<SCRIPT LANGUAGE='JavaScript'>window.open('file:\\server17a\shared\quality\qalerts\$filename','','toolbar=0,menubar=0,width=640,height=480');</script>";
When executed a window opens, but instead of the server17a document, it is a view of the "My Computer" file folder.
What am I doing wrong?
 
Hiya,
you should use forward slashes:

Code:
echo "<SCRIPT LANGUAGE='JavaScript'>window.open('file://server17a/shared/quality/qalerts/$filename','','toolbar=0,menubar=0,width=640,height=480');</script>";



JR
(In need of a cool signature)
 
The problem is that inside doublequotes, backslashes are interpreted as the escape character. The backslash and the next character are considered together.

However, this is not the case if you delineate your string using a single quote. The backslashes will be interpreted as simple backslash characters.

As an example, in this statement the "\n" combination will be interpreted as a newline:

echo "\new";

bue in this statement, the "\n" will be interpreted as "backslash n":

echo '\new';

Perhaps by modifying your line to use singlequotes you can get what you want.

I generally recommend in PHP using singlequotes to denote strings, particularly when outputting HTML. You don't have to escape the interior doublequotes that surround attribute values, and you get as output what you literally specify.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi m8,
I actually tried your suggestion last night as one of the first things. First I used escape chars which did not work.
Then I moved on to single qoutes, but no effect (I admit that it is easy to make a mistake with the piece of script above).

So finally used forward slashes / and voila! it worked great!

However thanks for some extra clarification on the double and single quote option. I have found your tips very helpful and look forward to reading the next.


JR
(In need of a cool signature)
 
Thank you both for the insight. Changing to forward slashes solved my problem.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top