Questions tagged [str-replace]

This function returns a string or an array with all occurrences of search in subject replaced with the given replace value.

The function str_replace() replaces all occurrences of the search string with the replacement string. It returns a string or an array with all occurrences of search in subject replaced with the given replace value.

Format on PHP

str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

Example

// Provides: Hll Wrld f PHP
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$onlyconsonants = str_replace($vowels, "", "Hello World of PHP");

References

2650 questions
0
votes
3 answers

How to replace integers with strings in formula in JavaScript

I wanted to replace desig values in my string formula to evaluate the expression. I have an array such as: var value_array = [ {value: "1", desig: "ABM"}, {value: "2", desig: "LF"}, {value: "3", desig: "DM"}, {value: "4", desig: "CM"}, …
alperzzz
  • 53
  • 5
0
votes
2 answers

preg-replace error

Can anyone find the solution for this error, $str= trim(strip_tags($str)); $str = preg_replace("']*>.*'siU",'',$str); $patterns = array(); $patterns[0] = '  '; $patterns[1] = '  '; $patterns[2] =…
Arun SS
  • 1,791
  • 8
  • 29
  • 48
0
votes
2 answers

str.replace() replace char with "char"

I have a script which processes data returned from a web API. The data returned is a string representation of a list of dictionaries. I know about ast.literal_eval() to convert the string representation of the dictionaries into real ones. The data…
MarkS
  • 1,455
  • 2
  • 21
  • 36
0
votes
1 answer

PHP: Optimize Find-and-replace procedure of many strings in single string

I'm auto-linking profiles existing on my site in blogpost texts which contain the profile names. To do so I... 1) ...extract currently ~500 rows (only?) from 4 different MySQL tables - containing different types of profiles - in a single database…
DanceMichi
  • 31
  • 4
0
votes
0 answers

Glype Proxy preg replace source

Pleas help me with this Glype proxy source code. I want to make a new proxy script but I have some big issue. When I access the website I get the styles and javascript src like this: src="/images/" And I want to change it with preg_replace or…
0
votes
1 answer

Replacing a deprecated create_function method

I'm in the process of updating an abandoned plugin and I've come across this deprecated function that I'm strugling to find a suitable replacement for. The original function is this: $callback = create_function( '', 'echo "' . str_replace(…
Venutius
  • 13
  • 6
0
votes
2 answers

PHP - Replace characters in a string

I have read a number of articles on str_replace() on here and other resources, and not found the answer to my problem. Here’s the string I have a problem with which is stored in $title ... Paul McCartney's Theme From The Film "The Honorary…
0
votes
1 answer

str_replace inside foreach loop

We are using str_replace to replace {$name} with $user['name'] from datebase, but its only replacing 1st entry of db, suppose there are 20 users, and 1st entry is 'tester' then it replace all {$name} with 1st entry only, check our code…
seoppc
  • 2,766
  • 7
  • 44
  • 76
0
votes
1 answer

Str_Replace Without Recalling the Function

How can I use str_replace in PHP without allowing it to re-replace the characters that have been used in the $replace_with in the following code?
Cecel
  • 27
  • 1
  • 5
0
votes
0 answers

How can I do a string replace only when it is preceded by a certain character with PHP?

I have a situation where I need to search a css file within PHP and replace all instances of the string 'logo.png' with whatever the client uploads. Let's say they upload 'logo.jpg' (notice the different file extension). My problem is that the css…
jmchauv
  • 147
  • 17
0
votes
2 answers

JavaScript replace single slash to double slash?

I currently have the following string with me var docPath="\\\\Server\Users\Files\Order\file1.pdf" Where in I need to replace the single backslashes to two back slashes in my ionic 3 mobile application like this var…
0
votes
4 answers

Why is PHP changing the first character after ltrim or str_replace?

I'm trying to remove a part of a directory with PHPs ltrim(), however the result is unexpected. The first letter of my result has the wrong ascii value, and shows up as missing character/box in the browser. Here is my code: $stripPath =…
iHaveacomputer
  • 1,427
  • 4
  • 14
  • 30
0
votes
1 answer

Str replace for input to button

I am trying to change wordpress search submit button to
wpdev
  • 195
  • 1
  • 12
0
votes
2 answers

Remove vowels from string C++

So I am new to C++ and tried to create a function that would remove vowels from a string, but I am failing at it horribly, Here is my code so far : #include using namespace std; string remove(string st) { for(int i = 0; st[i] != '\0';…
Muhammad Salman
  • 433
  • 6
  • 18
0
votes
2 answers

How to add html i tag to sub-strings that matched the elements of the array if they don't already have the tag

I want to add html i tag to substring in a string to those matched to the element of the array. If the matched substring has i tag then don't add else add. here's my sample code. function itilizedWords($subjects){ $arrayToSearch =…
Mamadou Barry
  • 297
  • 2
  • 7