Forum Moderators: coopster

Message Too Old, No Replies

path constant and strings

multiple strings, php constants, javascripts together

         

trotter

7:15 pm on Apr 21, 2009 (gmt 0)

10+ Year Member



I have defined the following two constants and they work properly, but I can't seem to get the syntax correct when replacing the "http://localhost/docs/people/" and adding the file name to it in the bottom code. The eleopen() and the ess.close() functions are javascript in external files.
-----------------------------------
define( 'PDOC_PATH', 'http://localhost/docs/people/' );
define( 'PIMG_PATH', 'http://localhost/gallery/people/' );
-----------------------------------
echo '<div class="econ"><a href="#" onClick="eleopen(event,"http://localhost/docs/people/013.php")" onMouseOut="ess.close()"><img src="http://localhost/gallery/people/013.jpg" width="123" height="151" alt="13"></a></div>';
-----------------------------------

Any assistance appreciated. An explaination would help me learn... I have been unable to find any book that explains it.

idfer

9:44 pm on Apr 21, 2009 (gmt 0)

10+ Year Member



Hi trotter and welcome to Webmasterworld. You want to change the code to this (i've bolded the relevant parts):

echo '<div class="econ"><a href="#" onClick="eleopen(event,"' . PDOC_PATH . '013.php")" onMouseOut="ess.close()"><img src="' . PIMG_PATH . '013.jpg" width="123" height="151" alt="13"></a></div>';

Basically, you're concatenating 5 string values together:

'<div...,"'
PDOC_PATH
'013.php...src="'
PIMG_PATH
'013.jpg...</div>'

The stuff between matching single-quotes (') can be anything. PHP doesn't care, it will concatenate all the strings together and send the result as is to the browser, whether it's HTML, javascript, or anything else. See the doc on Single quoted strings [php.net]

Constants are used like variables, except they're not preceded by the $ sign. See the doc on constants [php.net]

Hope this helps.

trotter

3:48 am on Apr 25, 2009 (gmt 0)

10+ Year Member



Thanks for your help... I knew it was something simple but it just escaped me. I have tried it on my pc at home (running wamp). It works, but when I put it on my site it will not. what is the difference.