How to print values in codeigniter?

by edmond_brakus , in category: PHP Frameworks , 22 days ago

How to print values in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by elise_daugherty , 21 days ago

@edmond_brakus 

In CodeIgniter, you can print values using the echo or print functions. You can also use the var_dump() or print_r() functions for printing arrays or objects.


Here's an example of how to print a value in CodeIgniter controller or view:


Controller:

1
2
$data = "Hello, CodeIgniter!";
echo $data;


View:

1
echo $data;


You can also load a view file and pass data to it using the CodeIgniter $this->load->view() function:


Controller:

1
2
$data = "Hello, CodeIgniter!";
$this->load->view('your_view', array('data' => $data));


View (your_view.php):

1
echo $data;


Remember to always escape any user input before displaying it in your views to prevent XSS attacks. You can use the htmlspecialchars() function for this.