PHP is more powerful and has a very rich built-in function. Experienced PHP programmers may be familiar with them, but many PHP learners are still unfamiliar with some very useful functions. In this article, we list 10 PHP functions that you may not understand but are useful for reference and learning.
1.php_check_syntax
This function can be used to check if the PHP syntax is correct in a particular file.
How to use:
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";}?>
Reference: http://www.php.net/manual/en/function.php-check-syntax.php
2.highlight_string
The highlight_string () function is useful when you want to display PHP code on a page, highlighting the PHP code you provide with the built-in syntax highlighting color. This function has two parameters, and the first parameter is the string to be highlighted. The second parameter, if set to true, returns the highlighted code.
How to use:
phphighlight_string(‘ ?>‘);?>
Reference: http://php.net/manual/en/function.highlight-string.php
3.show_source
This function is run and highlight_file()
similar, it can display the PHP syntax highlighted file, and is based on the HTML tag syntax highlighting.
How to use:
phpshow_source("php_script.php");?>
Reference: http://www.php.net/manual/en/function.show-source.php
4.php_strip_whitespace
This function is show_source()
similar to the above function, but it will delete the comments and whitespace in the file.
How to use:
phpecho php_strip_whitespace("php_script.php");?>
Reference: http://www.php.net/manual/en/function.php-strip-whitespace.php
5._halt_compiler
It can abort the execution of the compiler, which is useful for embedding data in PHP scripts, just like installing files.
How to use:
php$fp = fopen(__FILE__,‘r‘);fseek($fp, __COMPILER_HALT_OFFSET__);var_dump(stream_get_contents($fp));__halt_compiler();?>
Reference: http://www.php.net/manual/en/function.halt-compiler.php
6.highlight_file
This is a very useful php function, it can return the specified PHP file, and follow the syntax highlighting the contents of the file.
How to use:
phphighlight_file("php_script.php");?>
Reference: http://www.php.net/manual/en/function.highlight-file.php
7.ignore_user_abort
Using this function, the user can deny the browser end the request to execute the script. Normally, the client's exit causes the server-side script to stop running.
How to use:
phpignore_user_abort();?>
Reference: http://www.php.net/manual/en/function.ignore-user-abort.php
8.str_word_count
This function can be used to count the number of words in a string.
How to use:
phpecho str_word_count("Hello How Are You!");?>
Reference: http://php.net/manual/en/function.str-word-count.php
9.get_defined_vars
This function is important when debugging code, and it returns a multidimensional array that includes all of the defined variables.
How to use:
phpprint_r(get_defined_vars());?>
Reference: http://php.net/manual/en/function.get-defined-vars.php
10.get_browser
This function checks and reads browscap.ini
the file and returns browser-compatible information.
How to use:
phpecho $_SERVER[‘HTTP_USER_AGENT‘];$browser = get_browser();print_r($browser);?>
Reference: http://www.php.net/manual/en/function.get-browser.php
Article from: php100.com/html/dujia/2015/0128/8500.html
</span></span></span></span></span></span></span></span></ Span></span></span>
10 useful functions in PHP