Home  >  Article  >  Backend Development  >  What are the commonly used methods in php?

What are the commonly used methods in php?

coldplay.xixi
coldplay.xixiOriginal
2020-07-23 11:32:533480browse

Commonly used methods in php are: 1. [list()] assign the values ​​in the array to some variables; 2. [explode()] convert the string into an array; 3. [file_get_contents()] Read the entire file into a string; 4. [end()] gets the last parameter of the array.

What are the commonly used methods in php?

Commonly used methods in php are:

1. list()Put the array into Assign the value to some variables:

$my_array = array("Dog","Cat","Horse");
list($a, $b, $c) = $my_array;//或者
list($a, , $c) = $my_array;

2. explode()Convert the string into an array

$str = 'one,two,three,four';
// 零 limit
print_r(explode(',',$str,0));
// 正的 limit
print_r(explode(',',$str,2));
// 负的 limit
print_r(explode(',',$str,-1));

3.end()Get The last parameter of the array can only be variables and cannot contain methods.

4.file_get_contents()Read the entire file into a string.

5.is_uploaded_file() Determine whether the file is uploaded through HTTP POST.

6.move_uploaded_file()Move the uploaded file to a new location and save it.

7.file_exists()Check whether the file or directory exists.

8.mkdir($path,0777) Create a new directory chmod($path,0777) Rename the file mode and permissions.

9. Receive XML data using php:// .

     <?php
         $xmldata=file_get_contents("php://input");
        $data=simplexml_load_string($xmldata);
         print_r($data);
    ?>

10. String and array conversion.

$array = array(&#39;lastname&#39;, &#39;email&#39;, &#39;phone&#39;);
 $comma_separated = implode(",", $array);
 echo $comma_separated; // lastname,email,phone
 $pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
 echo $pieces[0]; // piece1
echo $pieces[1]; // piece2

Related learning recommendations: PHP programming from entry to proficiency

The above is the detailed content of What are the commonly used methods in php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more