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

SMS language Text expander - Pandas

Aim is to replace SMS in text with expansion. I achieve this by comparing stored column value in pandas and reading it in python as xlsx. word expansion fyi for your information gtg got to go brb be right back gtg2 got to go…
Programmer_nltk
  • 863
  • 16
  • 38
0
votes
4 answers

Replacing word in a string with another string - Javascript

Does anyone know any regex expression where I can replace a word found in a string with another string? var replacement = "car"; var toReplace = "boat"; var str = "banana boats or boat" str = str.replace(toReplace, replacement); I want str to be…
N.Car
  • 492
  • 1
  • 4
  • 14
0
votes
7 answers

JS: Replace whitespace with character

I'm trying to figure out how to replace all the whitespaces with a character given. My code is duplicating the character when the whitespace is replaced. This is the exercise, and my code so far: This function receives a string. It also takes an…
VisualXZ
  • 213
  • 3
  • 17
0
votes
0 answers

Get string between first open parentheses and last close parentheses

I need to get the string between the position of the first parenthesis and the position of the last parenthesis, to then make a str_replace between those parentheses, finally an explode to get the fields separated by commas something like…
Rwa
  • 15
  • 1
  • 6
0
votes
0 answers

Parse error: syntax error, unexpected '[', expecting

I'm getting an error and I don't know how to resolve it. The error is : Parse error: syntax error, unexpected '[', expecting ')' Code is : $message = str_replace(['\\', '"'], ['', '"'], crtl_data($_POST['message'])); I have checked the whole…
user5520871
0
votes
1 answer

How to replace an int value in String and adjust field length

I have like 120 img in HTML, that are loaded properly with Javascript when click event occurs. Then i get the attribute "src" from the img and store it in var currentModalImg_src. For example, i receive the image number 10, and i have this string…
user9324524
0
votes
2 answers

PHP remove a word (not characters) from a string

The problem with the code, below, is that it removes characters from the string rather than the words.
bagofmilk
  • 1,492
  • 8
  • 34
  • 69
0
votes
1 answer

stringreplace on Django

I need to do the 'string replace' on all my queryset, but I receive the following error: 'QuerySet' object has no attribute 'replace' def get_profilesJson_view(self): queryset =…
Mixo
  • 191
  • 13
0
votes
2 answers

PHP: Replace duplicate instances of string within array, more complex than it sounds

First time posting here after having great results searching for other answers on stackoverflow. I've hit a roadblock in an app I'm trying to build. It involves plotting a graph with JS using dynamic values pulled from a database. I'm at the point…
sagalbot
  • 118
  • 4
0
votes
3 answers

How to remove part from string strat from point or word?

I want to remove part of string from special world using php lang for example : $string1 = "xABCb1/DEF/GHI/GKL"; $string2 = "yABCz/DEF/MNO/PQR"; $string3 = "zABC1112/DEF/STU/VWX"; I want to remove all words before from (DEF) and the result looks…
KHALID
  • 87
  • 7
0
votes
2 answers

TypeError while doing replace() on encoded BeautifulSoup result in Python

Trying to encode the text output received after parsing HTML data through BeautifulSoup library in Python 3. Getting following error: ----> gmtext.encode('ascii', errors='replace').replace("?", "") TypeError: a bytes-like object is required, not…
guilemon
  • 132
  • 12
0
votes
4 answers

PHP open a php file and replace content

I wanna to open a php file and replace the content I tried this code but it didn't work, $fh = fopen("c/".$file."/underbaba.php", 'w'); $file = file_get_contents($fh); $file = str_replace('error":4,', 'error":0,', $file); This system open my file…
user6300103
0
votes
2 answers

How to select and run this function onload?

So I have this working codeblock in my script to replace the decimal seperator from comma "," into period "." ,when editing a form. Because in this region the decimal seperator comma is normal I also want the values to be displayed like this 1,99€…
Matte123
  • 3
  • 4
0
votes
2 answers

Issue replacing forward slash in string (php)

I have a very weird issue trying to do a simple str_replace in php in a wordpress application. I am trying to create a path to an image using wordpress functions to get the site path and the resource path. Below are 3 methods that I tried, all…
Bluekable
  • 61
  • 10
0
votes
1 answer

Unable replace \x.. sequence from a twitter feed in R

I've been grappling with regex in following string: "Just beautiful, let’s see how the next few days go. \n\nLong term buying opportunities could be around the corner \xed\xa0\xbd\xed\xb2\xb0\xed\xa0\xbd\xed\xb3\x89\xed\xa0\xbd\xed\xb2\xb8...…
user2582651
  • 33
  • 1
  • 8
1 2 3
99
100