Little-known 10 functions in PHP

Source: Internet
Author: User
Tags html tags memory usage php file php code cpu usage

  This article mainly introduces the little-known but very useful 10 functions in PHP, you need friends can refer to the following

PHP has very rich built-in functions, many we have used, but there are still a lot of functions we are not familiar with, but they are very useful. In this article, I've listed some little-known PHP functions that will brighten your eyes.   Levenshtein ()   Have you ever experienced the need to know how different two words are, this function is to help you solve this problem. It can compare the different degrees of two strings.   Usage:     code is as follows: <?php  $str 1 = "carrot";  $str 2 = "Carrrott";  Echo Levenshtein ($str 1, $st R2); Outputs 2 ?>      Get_defined_vars ()   This is a very useful function in debug debugging. This function returns a multidimensional array that contains all the variables that have been defined.   Usage:     code is as follows: <?php Print_r (Get_defined_vars ());?>     Php_check_syntax ()   This function is very Useful and can be used to check if the syntax of PHP is correct. For technical reasons, starting with PHP 5.05, this function was removed.   Usage:     code is as follows: <?php  $error _message = "";  $filename = "./php_script.php";  if (!php_che Ck_syntax ($filename, & $error _message)) {  echo "Errors were found in the file $filename: $error _message"; } else {  echo "The file $filename contained no syntax errors"; } ?>     Ignore_user_abort ()   This function is used to deny the browser-side user the request to terminate the execution of the script. A client's exit normally causesServer-side script stopped running.   Usage:     code as follows: <?php Ignore_user_abort ();?>     highlight_string ()   When you want to display the PHP code on the page , the highlight_string () function appears to be very useful. This function will highlight the defined colors in the built-in PHP syntax for the PHP code you provide. This function has two arguments, and the first argument is a string that indicates that the string needs to be highlighted. If the second argument is set to True, the function returns the highlighted code as the return value.   Usage:   code as follows: <?php highlight_string (' <?php phpinfo ();?> ');?>     Highlight_file   This is a very useful php function, it can return the specified PHP file, and in accordance with syntax semantics highlighting the contents of the file with a highlight color. The highlighted code is processed with HTML tags.   Usage:     code as follows: <?php highlight_file ("php_script.php");?>     Php_strip_whitespace   This function is similar to the previous show_source () function, but it deletes the annotations and spaces in the file.   Usage:   code as follows: <?php Echo php_strip_whitespace ("php_script.php");?>     Get_browser   This function will Read the Browscap.ini file to return browser-compatible information.   Usage:   code as follows: <?php echo $_server[' http_user_agent ']; $browser = Get_browser (); Print_r ($browser);?>     Memory_get_usage (), Memory_get_peak_usage (), Getrusage ()   These functions are used to obtain memory and CPU usage, MThe Emory_get_usage () function returns memory usage, the Memory_get_peak_usage () function returns peak memory usage, getrusage () returns the CPU usage, these functions give you some useful information when debugging PHP code performance. Note, however, that the windows on these functions are not valid.   Usage:     code is as follows: <?php  echo "Initial:". Memory_get_usage (). "Bytes N";  echo "Peak:". Memory_ge T_peak_usage (). "Bytes N";  $data = Getrusage ();  echo "User Time:" .  ($data [' ru_utime.tv_sec '] +  $d ata[' ru_utime.tv_usec '/1000000);  echo "System Time:" .  ($data [' ru_stime.tv_sec '] +  $data [' Ru_ Stime.tv_usec ']/1000000); ?>     gzcompress (), gzuncompress ()   These two functions are used to compress and decompress string data. Their compression rate can reach about 50%. Other functions Gzencode () and Gzdecode () can achieve similar results, but use different compression algorithms.   Usage:     code as follows: <?php  $string =  "Lorem ipsum dolor sit amet, consectetur  adipiscing Eli T. nunc ut elit id mi ultricies  adipiscing. Nulla Facilisi. Praesent pulvinar,  sapien vel feugiat vestibulum, nulla dui pretium orci,  non ultricies elit lacus quis ante. Lorem Ipsum Dolor&nbsP Sit amet, consectetur adipiscing elit. aliquam  pretium ullamcorper urna quis iaculis. Etiam ac massa  sed turpis tempor luctus. Curabitur sed nibh eu elit  mollis congue. Praesent ipsum diam, Consectetur vitae  ornare A, aliquam a nunc. In ID magna pellentesque  tellus posuere adipiscing. Sed non mi metus, at lacinia  Augue. Sed magna nisi, ornare in mollis, mollis  sed nunc. Etiam at Justo in Leo Congue mollis.  Nullam in neque eget metus hendrerit the EU scelerisque  non. Ut malesuada lacus EU nulla bibendum  ID euismod urna sodales. ";  $compressed = gzcompress ($string);  $original = gzuncompress ($compressed); ?>    Do you also think of other useful functions? Please share it in the comments!  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.