Skip to main content

Posts

Showing posts from December 24, 2017

PHP include() Vs require()

Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website. For example, if we want to create an instance of a class defined in the separate class file, then it has to be included before creating an instance of it. PHP provides various functions to include external files. The following list of functions is used to include external file into a PHP program.n this tutorial, we are going to compare these functions with suitable examples. Also, we are going to see the purpose of the _once usage and the difference between include and include_once/require and require_once. include() require() include_once() require_once() include(): PHP include() function includes external file into a PHP program. It accepts the external file path and checks if the file exists or not. If the file does not exist in the specified path, then the include() will return PHP warning. Warning : failed to open stream : No such file or directory ... W...

How to view and debug PHP arrays

Sometimes when coding or debugging in PHP, it’s helpful to see the entire contents of an array. An easy way to do this is with the print_r command. To make it more readable, wrap it in <pre> tags. For example, to see the contents of associative array $result: <pre> <? = print_r ( $result ) ?> </pre> You’ll see output like this: Array (     [key1] => value1     [key2] => value2     [key3] => value3 ) 1

How to rename a file or directory in ubuntu from terminal

There is no rename function in Ubuntu Linux. Instead, you simply move the file, giving it a new name. If you don’t actually mv it to another directory, then you have effectively renamed it: mv filename_original filename_new If you are trying to rename a directory, you need to use the -r recursive flag: mv -r original_directoryname new_directoryname