Introduce 10 useful functions in PHP

Source: Internet
Author: User
PHPMore powerful, with a very rich built-in function. Veteran of PHPProgrammers may be familiar with them, but a lot of PHPLearners, still unfamiliar with some very useful functions. In this article, we list 10 of the more useful PHPfunction, for your reference and learning. Okay, no more nonsense, let's get started!

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";}? >

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:

<?php    highlight_string (' <?php phpinfo ();?> ');? >

3. Show_source

This function is similar to Highlight_file (), it can display the PHP syntax highlighted file, and is based on the HTML tag syntax highlighting.

How to use:

<?php     Show_source ("php_script.php");?>

4. Php_strip_whitespace

This function is similar to the Show_source () function above, but it deletes comments and whitespace in the file.

How to use:

<?php    Echo php_strip_whitespace ("php_script.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));//The End of the Script Executionhalt_compiler ();?>

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:

<?php    highlight_file ("php_script.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:

<?php    ignore_user_abort ();? >

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 is you!");? >

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 ());? >

Ten. Get_browser

This function checks and reads the Browscap.ini file, returning browser-compatible information.

How to use:

<?phpecho $_server[' http_user_agent '; $browser = Get_browser ();p rint_r ($browser);? >

The above is the PHP 10 practical functions, hope that the students have a lot of help, more please search this site!

Related recommendations:
Basic structure of PHP functions

php function Trim () instance

PHP functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.