What are the commonly used methods in php?

coldplay.xixi
Release: 2023-03-03 06:34:02
Original
3488 people have browsed it

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;
Copy after login

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));
Copy after login

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);
    ?>
Copy after login

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
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template