Mohamed Athif Mohamed Athif - 1 year ago 71
PHP Question

Cant echo php echo as a string

i am trying to echo below. pure text.

<script src="<?php echo $config['dir_plugins']; ?>qroll.js"></script>

but it wont echo correctly.below is code.somehow it omits the echo as a a string and with it most of the other parts of the string.

$arr = array("qroll", "validate", "hellios");
$str2 = "src='<?php echo \$config[\'dir_plugins\']; ";
foreach ($arr as &$value) {
echo $str2;
echo $value;

it just returns

Answer Source

Following on from some comments, it appears that the user acutally wants to echo a string that includes some PHP in it.

If the desired output is:

src='<?php echo $config['dir_plugins']; ?>

Change your code to:

$str2 = "src='&lt;?php echo \$config['dir_plugins']; ?&gt;";

This will output:

src='<?php echo $config['dir_plugins']; ?>

Presumably the rest of the output (the script name and script tags) will be added by your code.

You are in effect escaping the HTML-incompatible parts of your output by converting < to &lt; and > to &gt;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download