pepe pepe - 1 year ago 77
PHP Question

How to mix PHP with a string inside CodeIgniter function?

I would like to dynamically set the

for each iteration of this radio button within a loop.

However have not been able to figure out the correct way of escaping strings and variables in the
portion. The quotes in that portion are failing to parse.

echo form_radio($data['filename'], 0, '', 'class="uniform" id="'$data['ids']'");

This uses the
helpers from CodeIgniter which have this layout.

Any idea how to solve this?

Answer Source

You must start with double quotes to get expanded variables, then escape nested ones with backslash

echo form_radio($data['filename'], 0, '', "class=\"uniform\" id=\"$data[ids]\""); 

Or use single quotes inside double

echo form_radio($data['filename'], 0, '', "class='uniform' id='$data[ids]'"); 

Notice you don't need to quote single dimensional array indexes inside the square braces if inside double quotes

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