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

PHP replace parts of a string and get the those replaced parts as separate strings

I have a string like, "[one]sdasf[two]sad[three]" So, I want to replace [one] with "replaced_one", [two] with "replaced_two". and I need those replaced values as separate strings. $rep_one = "replaced_one"; $rep_two = "replaced_two";
Mann
  • 576
  • 1
  • 9
  • 33
0
votes
4 answers

str_replace does not replace all the keys?

I'm making my own forum software. Well its normal to have smileys in your forum. So i made an array with all the smileys and putted them in a function: function si_ubb($string){ $smileys = array( '0<:)' => 'angelnot.gif', '>:('…
Thew
  • 15,789
  • 18
  • 59
  • 100
0
votes
1 answer

R str_replace_all Does Not Seem to Be Working Correctly

The following line of code does not appear to be working correctly for me: df$Combined2<-str_replace_all(df$Combined,"0[+]","") The string cell that I am questioning and trying to break apart follows: …
Zach
  • 37
  • 8
0
votes
2 answers

Str_replace with subject passed by reference

Given the following example: public function replaceMyText($search, $replace, &$content) { $newContent = str_replace($search, $replace, $content, $count = 1) $content = $newContent; } Can this cause a Warning that only variables can be…
LostCoder
  • 51
  • 1
  • 1
  • 5
0
votes
4 answers

Replace {{word}} in string

Have a string: $str = "Hello, {{first_name}} {{last_name}}!"; And variables $first, $last... in array $trans = array("{{first_name}}" => $first, "{{last_name}}" => $last, "{{cart}}" => $crt1, "{{phone}}" => $phone, "{{adds}}" => $addr,…
0
votes
6 answers

Can't calculate two values replacing certain sign

How can I add two values replacing / between them? I tried with item.replace("/","+") but it only places the + sign replacing / and does nothing else. For example If i try the logic on 2/1.5 and -3/-4.5, I get 2+1.5 and -3+-4.5. My intention here…
SIM
  • 21,997
  • 5
  • 37
  • 109
0
votes
2 answers

using str_replace to match whole words /case insensitive

I'm trying to replace whole words in a string using str_replace, however, even letters matched in words are being replaced. i tried preg_replace, but couldn't get it to work as i have a big list of words to replace. Any help is appreciated. $array2…
user2334436
  • 949
  • 5
  • 13
  • 34
0
votes
0 answers

Replace with change position with Php function for Local language to Unicode

eg. AcF to cFA Here AcF is other language and output is cFA it's UNICODE. when we write AcF then it must I have to write like cFA then its output in browser will the same ... AcF but it is now unicode... hits... unicode write as pronounce...…
0
votes
1 answer

PHP - str_replace dont work

(Sorry if my english is bad, but is not my language) In my PHP file I receive an object called $ orderdetalle that is generated in a part of the server where I do not have access and I don't know the encode of the server ...$ orderdetalle is an…
Exe
  • 101
  • 3
0
votes
1 answer

Replace spaces and ampersands with an underscore

I am attempting to loop through some variables and replace any instance of a space or an & with an underscore. I have it working for spaces, how would I go about adding the & as well? $(function() { $('div').each(function() { var str =…
user13286
  • 3,027
  • 9
  • 45
  • 100
0
votes
2 answers

Using replace() in tkinter for changing text input from space to -

Text1 = Text(root,height=1,width=15,background='grey') Text1.pack() Text1.replace(" ","-") So this is what i tried to do. I need to make all spaces typed in from the user to "-". So instead of "how are you" it should be "how-are-you". I've tried…
Daniel Saggo
  • 108
  • 1
  • 9
0
votes
1 answer

AHK: How to store the string "Brasília é do coração..." in a variable without losing the accents in autohotkey?

I have thoroughly searched for this aweful ahk remarked limitation. If you copy the text and use the clipboard it works fine, but if you declare var:="Brasília é do coração..." it stores "Brasília é do coração...".
0
votes
2 answers

"Parse error: Invalid numeric literal" php chr 039

I am trying to convert a weird single speech mark to a normal one in php. $str = str_replace(chr(039), "'", $str); I have found it is code 039 from many sources including https://www.atwebresults.com/ascii-codes.php?type=2. But it causes the "Parse…
Danny Keeley
  • 23
  • 1
  • 1
  • 6
0
votes
1 answer

Browser won't execute part of javascript code

I am currently working on a download of a watermarked image, and something strange is happening. When the image is watermarked it's src is DataURL and I want to replace part of the DataURL string to download it. But strangely the script just seems…
Tajlang
  • 41
  • 1
  • 5
0
votes
2 answers

Search the specific pattern and delete the pattern in a line in Python

I have specific pattern at the beginning of each line. I want to delete that particular pattern not the complete line in python. My data looks like after retrieving from the actual…