Page 1 of 1

string and value concatenation to be assigned to a constant

Posted: Sat Feb 17, 2007 12:34 am
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

Posted: Sat Feb 17, 2007 1:24 am
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"?>

Posted: Sat Feb 17, 2007 8:37 am
by feyd
Quotes need to be around the string or it will be variables to Javascript.