CodeIgniter Forums
Display Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Display Problem (/showthread.php?tid=41150)



Display Problem - El Forum - 04-29-2011

[eluser]jvk22[/eluser]
I am making a code generator and when I try to display php tags ex. <?php ?> that are saved in a variable, nothing displays.

Here's the code
Code:
foreach ($fields as $field)
{
    $database_fields[] = $field;
    echo $field;
    $add_form_values = '<?php echo form_input($'.$field.'_attr); ?>';
}
echo $add_form_values;



Display Problem - El Forum - 04-29-2011

[eluser]skiter[/eluser]
Code:
foreach ($fields as $field)
{
    $database_fields[] = $field;
    echo $field;
    $add_form_values = form_input($field); //or $this->form_input($field)
}
echo $add_form_values;



Display Problem - El Forum - 04-29-2011

[eluser]jvk22[/eluser]
No that's not the issue. I'm making a code generator and I need to be able to store <?php ?> tags into a variable so I can save them to a file, however every time I try to put the php tags in a variable, and echo is out, nothing displays.

What should echo out is
<?php echo form_input($FIELD_NAME_attr); ?>

So I can then take that code and save it to a php file.


Display Problem - El Forum - 04-29-2011

[eluser]toopay[/eluser]
[quote author="jvk22" date="1304113840"]...however every time I try to put the php tags in a variable, and echo is out, nothing displays.[/quote]
Did you try to see the source? CTRL+U. If php tag correctly rendered, then you'll see them.
[quote author="jvk22" date="1304113840"]
What should echo out is
<?php echo form_input($FIELD_NAME_attr); ?>[/quote]
To display it on a browser, try this...
Code:
$var = htmlspecialchars('<?php echo $var ?>');
echo $var;
to decode it, when you want to save it into a file, use
Code:
htmlspecialchars_decode($var);



Display Problem - El Forum - 04-29-2011

[eluser]jvk22[/eluser]
That worked, thanks.