Page 1 of 1

Javascript and PHP

Posted: Tue Sep 02, 2003 4:25 pm
by maldar
i have a function that makes me short html header for my pages such this:

Code: Select all

function short_header(some parameter){
?>
<HTML >
   <HEAD>
   <TITLE> <? echo $page_title; ?> </TITLE>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET= <?php echo $cfg_charset ; ?> ">
   <LINK REL="stylesheet" TYPE="text/css" HREF="<?php if(isset($styfile)) echo $styfile;?>">
   <Script >
	???????????? how import javascript file here  
    </Script>
   </HEAD>
   <BODY background="<?php if(isset($bg)) echo $bg; ?>">
<?
&#125;
now i want to call this function with a javascript file (*.js) as one of its parameter to use it everywhere it is needed. my question is :how can i use this parameter in my function?.Please help me

Posted: Tue Sep 02, 2003 4:29 pm
by JayBird

Posted: Sat Sep 06, 2003 3:27 pm
by maldar
found nothing usefull at there,except a similar question
i want to write my diferent javascript in seperate file and call one of these files on one or more pages when thay are needful .

do you mean

Posted: Sat Sep 06, 2003 3:41 pm
by phpScott

Code: Select all

<script language="javascript" src="location/of_my/javascript/file.js"></script>
just remeber to escape the quotes in the script tag

this will allow you to use all the functions in the js file.

phpScott

Posted: Sat Sep 06, 2003 4:11 pm
by maldar
i wrote this in my function:
$spt is my function parameter name for javascript filename

Code: Select all

<script language="javascript" src="<?echo $_SERVER&#1111;DOCUMENT_ROOT]/us/js/$spt.js; ?>"> </script>
but i recieved this error in created html file:

Code: Select all

<script language="javascript" src="<br />
<b>Warning</b>:  Division by zero in <b>c:\www\us\inc\output.fns.php</b> on line <b>68</b><br />
<br />
<b>Warning</b>:  Division by zero in <b>c:\www\us\inc\output.fns.php</b> on line <b>68</b><br />
<br />
<b>Warning</b>:  Division by zero in <b>c:\www\us\inc\output.fns.php</b> on line <b>68</b><br />
js"> </script>
and on line 68 of output.fns.php i wrote script tag.

i'm wonderful why this happen :?: :!:

what is wrong?

slash problem

Posted: Sat Sep 06, 2003 4:31 pm
by phpScott

Code: Select all

&lt;script language="javascript" src="&lt;?echo $_SERVER&#1111;DOCUMENT_ROOT]/us/js/$spt.js; ?&gt;"&gt; &lt;/script&gt;
No worries it is a simple problem to fix.

What is happening is that the / is also the symbol for divide by as in 4/2=2 so the eaisest way to fix your script is to change your slashes form / to \ however the \ is seen as an escape character and as in \n for new line or \r for carriage return. So you have to escape the \ with a \ as in \\us\\js\\$spt.js So your code should look like

Code: Select all

<script language="javascript" src="<?echo $_SERVER[DOCUMENT_ROOT]\\us\\js\\$spt.js; ?>"> </script>
make sense.

Hope this works for you

phpScott

Posted: Sat Sep 06, 2003 4:43 pm
by maldar
Thanks a lot phpScott
but it does not work
i found the problem and solve it on this simple way:

Code: Select all

<script language="javascript" src="<?echo "$_SERVER&#1111;DOCUMENT_ROOT]/us/js/$spt.js"; ?>"> </script>
yes only by adding " at begin and end of echo string. 8)

again thank you for your reply. :P

hope this be useful for others

yes

Posted: Sun Sep 07, 2003 2:29 pm
by phpScott
silly quotes I still have trouble with them.

The " will interpret the stuff inside as a sting and not as a sequence of commands or actions.

phpScott