Thay thế số trong chuỗi php

Trong bài viết này, chúng ta sẽ xem cách thay thế sự xuất hiện của chuỗi tìm kiếm bằng chuỗi thay thế bằng cách sử dụng hàm str_replace[] trong PHP, cùng với việc hiểu cách triển khai của chúng thông qua các ví dụ

str_replace[] là một hàm tích hợp trong PHP và được sử dụng để thay thế tất cả các lần xuất hiện của chuỗi tìm kiếm hoặc mảng chuỗi tìm kiếm bằng chuỗi thay thế hoặc mảng chuỗi thay thế trong chuỗi hoặc mảng đã cho tương ứng.  

cú pháp.  

str_replace [ $searchVal, $replaceVal, $subjectVal, $count ]

Thông số. Hàm này chấp nhận 4 tham số trong đó 3 tham số bắt buộc và 1 tham số tùy chọn. Tất cả các thông số này được mô tả dưới đây.  

  • $searchVal. Tham số này có thể thuộc cả kiểu chuỗi và kiểu mảng. Tham số này chỉ định chuỗi được tìm kiếm và thay thế
  • $replaceVal. Tham số này có thể thuộc cả kiểu chuỗi và kiểu mảng. Tham số này chỉ định chuỗi mà chúng tôi muốn thay thế chuỗi $searchVal
  • $subjectVal. Tham số này có thể thuộc cả kiểu chuỗi và kiểu mảng. Tham số này chỉ định chuỗi hoặc mảng chuỗi mà chúng tôi muốn tìm kiếm $searchVal và thay thế bằng $replaceVal
  • số lượng $. Tham số này là tùy chọn và nếu được thông qua, giá trị của nó sẽ được đặt thành tổng số thao tác thay thế được thực hiện trên chuỗi $subjectVal

Giá trị trả về. Hàm này trả về một chuỗi hoặc một mảng dựa trên tham số $subjectVal với các giá trị được thay thế

Cách tiếp cận. Nếu đối số $searchVal và $replaceVal là mảng, thì tất cả các phần tử của đối số $searchVal được tìm kiếm trong chuỗi $subjectVal và được thay thế bằng các phần tử tương ứng trong đối số $replaceVal. Nếu một số phần tử trong mảng $replaceVal ít hơn số phần tử trong mảng $searchVal, thì nếu có bất kỳ sự xuất hiện nào của các phần tử bổ sung của đối số $searchVal trong đối số $subjectVal thì chúng sẽ được thay thế bằng một chuỗi rỗng. Nếu tham số $subjectVal cũng là một mảng thay vì một chuỗi thì tất cả các phần tử của $subjectVal sẽ được tìm kiếm

Xem xét ví dụ dưới đây.   

Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.

ví dụ 1. Ví dụ dưới đây minh họa hàm str_replace[] trong PHP

PHP




Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
0

 

Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
1
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
2

Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
1
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
4
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
5
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
0
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
1

 

Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
1
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
3

Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
1
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
5
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
5_______17
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
8
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
9
It was nice meeting him. May him shine bright.
0
It was nice meeting him. May him shine bright.
1
It was nice meeting him. May him shine bright.
0
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
4
It was nice meeting him. May him shine bright.
4

_______41____96____15_______94

It was nice meeting him. May him shine bright.
9

đầu ra

It was nice meeting him. May him shine bright.

ví dụ 2. Ví dụ này mô tả việc thay thế tất cả các chuỗi tìm kiếm bằng cách thay thế các chuỗi bằng cách sử dụng hàm str_replace[]

PHP




Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
0

 

Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
1
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
2

Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
1
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
84 
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
5______186
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
1

 

Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
1____189

Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
1
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
01
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
5_______403
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
8
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
05
It was nice meeting him. May him shine bright.
0
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
07
It was nice meeting him. May him shine bright.
0
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
09
It was nice meeting him. May him shine bright.
4

 

_______41____412

Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
1
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
14
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
5_______403
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
8
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
18
It was nice meeting him. May him shine bright.
0
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
20
It was nice meeting him. May him shine bright.
0
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
22
It was nice meeting him. May him shine bright.
4

 

_______41____425

Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
1
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
27
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
5_______17
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
8
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
01
It was nice meeting him. May him shine bright.
0
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
14
It was nice meeting him. May him shine bright.
0
Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
84
It was nice meeting him. May him shine bright.
4

_______41____96____427

It was nice meeting him. May him shine bright.
4

It was nice meeting him. May him shine bright.
9

đầu ra

Input:  $subjectVal  = "It was nice meeting you. May you shine brightly."
        str_replace['you', 'him', $subjectVal]
Output: It was nice meeting him. May him shine brightly.
Explanation: Every occurrence of you is replaced with him.

Input:  $subjectVal  = "You eat fruits, vegetables, fiber every day."
        $searchVal = array["fruits", "vegetables", "fiber"]
        $replaceVal = array["pizza", "beer", "ice cream"]
        str_replace[$array1, $array2, $str]
Output: You eat pizza, beer, ice cream every day.
Explanation: Since both the arguments are arrays, therefore, 
every element from the first argument is replaced with 
the corresponding element from the second argument.
8

Tài liệu tham khảo. http. //php. net/thủ công/vi/chức năng. thay thế str. php

PHP là ngôn ngữ kịch bản phía máy chủ được thiết kế dành riêng cho phát triển web. Bạn có thể học PHP từ đầu bằng cách làm theo Hướng dẫn PHP và Ví dụ về PHP này

Chủ Đề