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
1 answer

Replace a column of various strings

I am doing some EDA on the PUBG data from the Kaggle competition. I would like to convert the common game modes into the standard form Solo, Duo, Squad, Flare and Crash Here is a list of unique values: {'flaretpp', 'crashtpp', 'squad-fpp',…
theotheraussie
  • 495
  • 1
  • 4
  • 14
0
votes
1 answer

str_replace - how to handle special circumstances?

Possible Duplicate: PHP str_replace with for loop from array How to replace a string (#stringA#) with elements from an array?... let's say we've a text: 'My shoes are #stringA# but #stringA#' (the same string - #stringA#) with $array: $array[0] =…
0
votes
1 answer

PHP str_replace with array() gets nested overwriting replaced values

I want to replace words with tagged words in text. tbl_glossary id word 1 apple pie 2 apple 3 juice The words are in array from database (MySQL). Then word gets replaced with replaced word if the word contains the same value (e.g. 'apple…
chloe
  • 119
  • 11
0
votes
1 answer

How to use %in% to make string replacements (str_replace) in R

I am trying to find an elegant way to use %in% and str_replace() to clean up gender. I know I can use regx() to do the same thing, but am looking at alternative ways to tackle the same problem. My code is: sex <- c("Male","girl","boy",…
richcru
  • 3
  • 1
  • 3
0
votes
2 answers

PHP How to match exact numbers and symbols in a string using preg_match?

I'm parsing some data and standardizing it for my website. The data I get from parsing: [sizes] => Array ( [0] => 5 [1] => 6 [2] => 10 [3] => 6+ [4] => 7 [5] => 7+ [6] => 8 [7] =>…
Sanamarina
  • 25
  • 5
0
votes
1 answer

Problems removing HTTP:// from string (unserialized key)

I have urls that I need to remove either http:// or https:// from the string. So example I would like; http://www.google.co.uk to become just www.google.co.uk https://www.yahoo.com to become just www.yahoo.com The string ($url) is being retrieved…
Gizz
  • 1
  • 3
0
votes
1 answer

dplyr string match and replace based on lookup table in R

I'm trying to achieve a function that I previously did in Excel, but having trouble finding a means to achieve it. I have two datasets: one is my base dataset and the other is a lookup table. My base has two columns, the first and last names of…
Pryore
  • 510
  • 9
  • 22
0
votes
1 answer

mutate() and str_replace() function

I'm trying to remove any strings that contains the word "Seattle" in the column named "County" in the table named Population Population %>% mutate( str_replace(County, "Seattle", "")) It gives me an error message.
0
votes
2 answers

HTML tag inside javascript eval() function

Why in the first case, html em tags are printed normally whereas in the second test, they disappear. var text = "text"; eval("var text = text.replace(/(.*)(ex)(.*)/gi,'$1$2$3');"); console.log(text) //text -> text but var…
redochka
  • 12,345
  • 14
  • 66
  • 79
0
votes
2 answers

Replacing words in a file, using another file in PHP

I have a file with a passage on it (Assignment2inputfile.txt). I can open that file just fine. I have another file (stopwords) that has a list of words that, if found in Assignment2inputfile, need to be replaced with the word "stop" (I put it in all…
Kari
  • 115
  • 1
  • 1
  • 10
0
votes
1 answer

PHP replace text inside specific text

I'm using str_replace to replace a simple shortcode which works fine: $content = "[old_shortcode]"; $old_shortcode = "[old_shortcode]"; $new_shortcode = "[new_shortcode]"; echo str_replace($old_shortcode, $new_shortcode, $content); However I want…
The Bobster
  • 573
  • 4
  • 20
0
votes
2 answers

How to change string inside word only once using str_replace or other function?

I need to chnage some words inside strings - I must separate string on 2 or more words - or to add space before and after word. For example I have shopifystore - this must be separated into 2 words": shopify and store, so result must be: "shopify…
Eduard Dimitrov
  • 152
  • 2
  • 10
0
votes
1 answer

STR_Replace Issues With Soap Envelope

I am trying to use the str_replace() function to remove the S:Envelope and S:Body tags from my Soap XML output. Despite many attempts I have been unable to remove these tags. I need to remove the tags so that I can pull data from the XML output…
mugelloblue
  • 137
  • 1
  • 11
0
votes
2 answers

How to remove/replace certain characters from both keys and values in an array?

My goal is to remove a group of characters from a one dimensional array's keys and another group of characters from that same array's values. Example: $arr = [ 'a' => 'Letter A!', '`b`' => 'Letter B w/quotes...', ' c ' => 'Letter C…
CPHPython
  • 12,379
  • 5
  • 59
  • 71
0
votes
2 answers

PHP insensitive replace

I am trying to insensitive replace string, so I'm using str_ireplace() but it does something I dont want and I have no clue how to overcome this problem. so this is my code: $q = "pArty"; $str = "PARty all day long"; echo str_ireplace($q,'' . $q…
Ron
  • 3,975
  • 17
  • 80
  • 130