Home > Article > Backend Development > 5 PHP practical functions to share
Senior PHP programmers may be familiar with them, but many PHP learners are still not familiar with some very useful functions. In this article, we list 10 useful PHP functions that you may not know but are useful. We hope they can help you.
The highlight_string() function is very useful when you want to display PHP code on the page. It can use the built-in defined syntax Highlight color highlights the PHP code you provide. This function takes two parameters, the first parameter is the string to be highlighted. If the second parameter is set to TRUE, the highlighted code will be returned.
Usage:
<?php highlight_string(' <?php phpinfo(); ?>'); ?>
2.show_source
The operation of this function is similar to highlight_file(). It can display the PHP syntax highlighted file and is based on HTML Tags are syntax highlighted.
Usage:
<?php show_source("php_script.php"); ?>
3.php_check_syntax
This function can be used to check whether the PHP syntax in a specific file is correct.
Usage:
<?php $error_message = ""; $filename = "./php_script.php"; if(!php_check_syntax($filename, &$error_message)) { echo "Errors were found in the file $filename: $error_message"; } else { echo "The file $filename contained no syntax errors"; } ?>
4.php_strip_whitespace
This function is similar to the show_source() function above, but it will delete comments and spaces in the file.
Usage:
<?php echo php_strip_whitespace("php_script.php"); ?>
5._halt_compiler
It can halt the execution of the compiler, which is helpful for embedding data in PHP scripts, like installation Files are the same.
Usage:
<?php $fp = fopen(__FILE__, 'r'); fseek($fp, __COMPILER_HALT_OFFSET__); var_dump(stream_get_contents($fp)); __halt_compiler(); ?>
The above is the detailed content of 5 PHP practical functions to share. For more information, please follow other related articles on the PHP Chinese website!