Contenate User Global in Inline Style

I can’t seem to work out the syntax for adding a user defined global variable value into an inline style that uses single quotes.

This is the line as it is and working:

$Output .= "<img id=\"".COMMON_REL_IMAGES."refreshicon.gif\" style='border: 1px solid #CBD8E5;' src='/common/icaptcha/imagick.php?img=' + Math.random();/>";

. . . but I want to add another value something like ths:

$Output .= "<img id=\"".COMMON_REL_IMAGES."refreshicon.gif\" style='border: 1px solid #CBD8E5;' src='.COMMON_REL_ICAPTCHA.'imagick.php?img=' + Math.random();/>";

As it uses single quotes, the variable becomes a string rather than the value. How is that done?

The string is overall double-quoted. To concatenate anything with it, you would use a double-quote to close/end the current fragment of the string, then concentrate the value, then use a double-quote to open/begin the next fragment of the string.

I recommend that instead of using escaped double-quotes around attribute values, that you simply use single-quotes, like the rest of the string is already doing.

I typically use double quotes for string-based items and HTML values but for inline Styles (which I very rarely use) and inline JavaScript, I use single quotes but you’re right, it is overall double quoted. Knowing that it was double-quoted, I did try concatenating it the way I usually do but apparently didn’t quite get it right as I still get only the variable and not the value in the resulting source code.

After converting the two escaped double-quotes, to single-quotes -

$Output .= "<img id='".COMMON_REL_IMAGES."refreshicon.gif'
 style='border: 1px solid #CBD8E5;'
 src='".COMMON_REL_ICAPTCHA."imagick.php?img=' + Math.random();/>";

Thank you, it works perfectly! I was sure that was the very thing I had tried the first time that didn’t work but I must have had something off a bit. I put it to good use on the second line of code where it also works perfectly.

$Output .= "<img id='".COMMON_REL_IMAGES."refreshicon.gif' style='border: 1px solid #CBD8E5;' src='".COMMON_REL_ICAPTCHA."imagick.php?img=' + Math.random();/>";
$Output .= "<a href=\"#\" onclick=\"document.getElementById('".COMMON_REL_IMAGES."refreshicon.gif').src='".COMMON_REL_ICAPTCHA."imagick.php?img=' + Math.random(); return false\">\n";
Sponsor our Newsletter | Privacy Policy | Terms of Service