string and value concatenation to be assigned to a constant

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
daibutsu
Forum Newbie
Posts: 1
Joined: Fri Feb 16, 2007 11:23 pm

string and value concatenation to be assigned to a constant

Post by daibutsu »

Dear all,


I have to replace a split string by a php constant; but the string has text part concatenated with value of the variables. If I assign the concatenated string to a php constant, it does not evaluate the variable value when displayed. eg:


res = confirm("The file at " + filename.value + "is added to project(<? echo $varProjname ?>)" );

is to be replaced as:

res = confirm(<? echo $CONST_WHOLE_STRING ?>);

But when I replaced as above, the variable does not get evaluated and gives error.


So please help me in solving this problem of replacing a concatenated string with a php constant.


thanks

buddha
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

constants aren't preceded by the dollar sign...

Code: Select all

<?php
define('CONST_WHOLE_STRING', 'Value');
?>
res = confirm(<?php echo CONST_WHOLE_STRING; ?>);
Also, don't use php short tags (<? ?>) use the standard php tags instead (<?php ?>). PHP is dropping support for short tags ( I believe). They aren't available on all installs, (so they are not very portable), and I I'm pretty sure they cause problems with xml when enabled

Code: Select all

<?xml version="1.0"?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Quotes need to be around the string or it will be variables to Javascript.
Post Reply