Javascript and PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maldar
Forum Commoner
Posts: 49
Joined: Mon Aug 18, 2003 4:39 pm

Javascript and PHP

Post 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
Last edited by maldar on Sat Sep 06, 2003 3:38 pm, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

maldar
Forum Commoner
Posts: 49
Joined: Mon Aug 18, 2003 4:39 pm

Post 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 .
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

do you mean

Post 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
maldar
Forum Commoner
Posts: 49
Joined: Mon Aug 18, 2003 4:39 pm

Post 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?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

slash problem

Post 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
maldar
Forum Commoner
Posts: 49
Joined: Mon Aug 18, 2003 4:39 pm

Post 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
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

yes

Post 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
Post Reply