Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to replace string in PHP

Tags:

string

php

I need to replace some string in a PHP code to make it look better. What would be the best way to go about that?

like image 208
Chirag Avatar asked Oct 06 '10 06:10

Chirag


People also ask

How can I replace multiple words in a string in PHP?

Approach 1: Using the str_replace() and str_split() functions in PHP. The str_replace() function is used to replace multiple characters in a string and it takes in three parameters. The first parameter is the array of characters to replace.

How can I replace part of a string in PHP?

The str_replace() function replaces some characters with some other characters in a string. This function works by the following rules: If the string to be searched is an array, it returns an array. If the string to be searched is an array, find and replace is performed with every array element.

How can I replace one word with another in PHP?

Answer: Use the PHP str_replace() function You can use the PHP str_replace() function to replace all the occurrences of a word within a string.


1 Answers

The usual suspects would be str_replace and preg_replace.

like image 150
Joey Avatar answered Sep 28 '22 00:09

Joey