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

How do i replace characters in a regex preg replace in the dollar sign 1 ($1) only?

Let's say I have this preg replace: $emailnote = preg_replace('@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@', '$1', $emailnote); It's replacing text url's…
leoarce
  • 567
  • 2
  • 8
  • 33
0
votes
2 answers

Skip Over Words/Phrases if In Quotes while doing String Replacement/Removal

Let's say I have a string like this I am flying from "Detroit to Vancouver" this July $string = 'I am flying from "Detroit to Vancouver" this July'; I also have an array of "stopwords" (words that I'm choosing to remove from the…
bbruman
  • 667
  • 4
  • 20
0
votes
1 answer

How to replace a (ring) for a in Python?

I have a list with some thousands strings. Some strings have & that should be replaced by and some strings have % that should be replaced for and so on. There are many rules. There are some strings with this special character a(ring) that should…
IgorAlves
  • 5,086
  • 10
  • 52
  • 83
0
votes
1 answer

Replace multiple string in a file java

I am trying to replace multiple strings in a file from source as ArrayList. But the application is erasing the old string before replacing a new one. Please help. public static void writeNewFile(File template, ArrayList data) { File…
roj
  • 59
  • 4
0
votes
1 answer

How to replace comma followed multiple spaces and & symbol with & using preg_replace

Am trying to replace comma followed by multiple spaces and & symbol with & using php. Is there any way to do it example: a, & b. expected output: a & b. I have tried but it works for only single space. doesn't work for multiple dynamic…
0
votes
1 answer

Strip everything except one word in PHP

Searched up and down, but I couldn't find anything that works. I want to strip everything except you. $words = "you,us,them,our"; $keep = "you,"; This does the opposite: $words = str_replace("$keep", "", $words); How do I strip everything except…
0
votes
2 answers

replacing ".html" inside a href with Wordpress

I have a wordpress site with lots of links in it. Every link has the extension ".html" (like
0
votes
2 answers

How to replace a hashtag followed by a number?

I want to replace as FALSE where the string contains a # followed by an integer. This is my code: $newlogicexpression = '#1 and (1743327.12 > 10)'; if( strpos( $newlogicexpression, '#' ) !== false ) { $newlogicexpression = str_replace('#',…
Shiromi
  • 159
  • 1
  • 9
0
votes
0 answers

How to pass the hash (#) through Uri.parse

I want to pass a # through Uri.parse. Now I am getting the value in the number variable but when I click on the button, the # suddenly disappears, why does this happen? list_But.setOnClickListener(new View.OnClickListener() { @Override …
0
votes
2 answers

remove specific character unless preceded by some specific string

I looked a lot, but i couldn't find answer to my case. So I want to remove specific character unless it is preceded by some specific string. For example, if I have a paragraph like follows var para = ' >Lorem ipsum dolor sit…
Amer Bearat
  • 876
  • 2
  • 7
  • 25
0
votes
1 answer

str_replace with ob_get_contents buffer is not working on website but works under testing?

I am playing with dynamic header titles, descriptions and canonical. I am having some trouble explaining and figuring out what is going on here. I am copying the exact same sample as below into my existing live website, but for some reason on my…
ii iml0sto1
  • 1,654
  • 19
  • 37
0
votes
1 answer

string_replace replacing very first segment in loop

This question is based on my previous question. This is my code. $this->logger->debug($datauser); // [ZN1961] => Array([#A] => 12 > 4 [#B] => 12 > 2 ), [ZN1962] => Array ([#A] => 20 > 4 [#B] => 20 > 2 ) logicexpression = ((#A) OR (#B)…
Shiromi
  • 159
  • 1
  • 9
0
votes
1 answer

Str_replace in foreach loop php

I want to replace several strings in an iteration pattern. foreach (self::model()->findAll($q) as $ruleSet) { $stringSet =$ruleSet->logic; // It gives as "1 AND 2" $dataset = array (); foreach (CampaignAutoLogic::model()->findAll($q)…
Shiromi
  • 159
  • 1
  • 9
0
votes
2 answers

Perl Regex Replacement

I'm pretty new to Perl and have the following issue: I'm trying to replace a version number in a .yml file with a different value. This is what my regex looks like: version:\s*([^\s]+) It works so far, but it does not do what I like it to do. Here…
Stefan
  • 214
  • 1
  • 12
0
votes
1 answer

How can I replace multiple Strings with str_replace?

How can I replace multiple strings with str_replace? $oldurl = JFactory::getURI(); $newurl = str_replace('example1', 'replacedwiththis', $oldurl); but I need that this code works also if the URL contains example2. So I need a code that changes both…