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 a char in a specific index with another char on another index

The following code prints eleelde but I want it to print elcaalde. How can I do it? Is there a function like replace char at index()?? I want to assign the character at i=0 the value of the char at i=6 and print the word elcaalde. public class…
0
votes
2 answers

Replace function in JavaScript By variable

I need to replace $ by Random how can I do this. I want to convert this text from Some texte here some text here to be like this Som(gb5t2)e t(gb95f)ext(ze6f5)e h(bs3e2)ere (avFe3)so(gEC3e)me (aFE98)tex(8FZq2)t h(dq9aA)ere(cZ3cC). function String()…
Msf007
  • 3
  • 4
0
votes
1 answer

php str_replace produces strange results

I am trying to replace some characters in a text block. All of the replacements are working except the one at the beginning of the string variable. The text block contains: [FIRST_NAME] [LAST_NAME], This message is to inform you that... The…
Andrew
  • 63
  • 1
  • 6
0
votes
1 answer

replace multiple words that look the same in a string

I have a little problem in PHP. $string = "[:string] has [:int] [:string] and [:int] [:string]"; I just wanna modify (probably with str_replace) it with: $string = "He has 5 apples and 3 bananas"; How could I do that? (Classic str_replace() will…
0
votes
3 answers

Getting Server's Root Path

Getting the root to the site's folder isn't difficult but I am trying to get the folder in which all sites are located rather than the root folder of a specific site. I have been using the code below but I came across an instance affecting…
DonP
  • 725
  • 1
  • 8
  • 27
0
votes
1 answer

Replace words in a string using multidimensional array of contents

I am using str_replace : foreach( $languages as $lang ) { $html = str_replace( $lang['english'], $lang['german'], $html ); } The $languages array contains : $languages =…
Isaac
  • 1
  • 1
  • 6
0
votes
2 answers

How to use preg_replace on a URL

How do I use preg_replace text/url. For example, I have a url like this: http://www.web.org/dorama/1201102144/hitoya-no-toge. I just want to show web.org. The url is not always same, for example sometimes it's: http://www.web.org/movies/123/no…
jazuly aja
  • 89
  • 10
0
votes
0 answers

Amend $my_post['post_content'] to show description as well as title of the post

Sir, I wants to amend my php code so that it will show post description and post title simultaneous. The undermentioned php code is to replace my Wordpress Post title with Coupon Title: $my_post['post_title'] = str_replace("&", "and",…
Pradeep
  • 1
  • 2
0
votes
3 answers

Find, replace and print out updated string

I am trying to create a python script that has 10-20 lines of fixed data in a string with 2 special character's that need to be replaced with a different, random string using randomword() import random, string def randomword(length): letters =…
0
votes
1 answer

Google Maps question to obtain coordinates in php

This is on php I have the following variable on an array Array ( [0] => { "name": "BRAVO Mario1050 [1] => Capital Federal [2] => Argentina" [3] => "Status": { "code": 200 [4] => "request": "geocode" } [5] => "Placemark": [ { "id": "p1" [6] =>…
Saikios
  • 3,623
  • 7
  • 37
  • 51
0
votes
1 answer

str_replace() not working with while loop with variable for search argument

$query1 = mysqli_query($cone,"SELECT words FROM banlist ORDER BY words") or die(mysql_error()); while($row = mysqli_fetch_array($query1, MYSQLI_ASSOC)) { $fix = (string)$row['words']; $title = str_replace($fix, "-",…
0
votes
3 answers

How to replace multiple strings with one string with downcase in python?

I need to write a function which replaces multiple format strings into downcase. For example, a paragraph contains a word 'something' in different formats like 'Something', 'SomeThing', 'SOMETHING', 'SomeTHing' need to convert all format words into…
prasannaboga
  • 1,004
  • 1
  • 14
  • 36
0
votes
0 answers

Replace hex colors to colors

I have the code and I need to replace hex colors code to real color in PHP.
0
votes
2 answers

Edit text from php document

I have this php document called: pdf5.php In that document I have these lines : $pdf->setSourceFile('h.pdf'); I want to be able to edit these lines 'h.pdf' with a code or script. The problem is that I would like to do it this way: I have…
Norman
  • 79
  • 1
  • 1
  • 7
0
votes
2 answers

Trouble with regex / preg_match / str_replace with complicated string

I am having trouble with a complicated regex. I have tried this every way I can think of, and I can always only get "almost" there -- I have a block of 5 messages: ---Agent 1: Wednesday 08/16/2017 | 11:43 AM --- Message 1 --- Agent 1: Friday…
Zak
  • 6,976
  • 2
  • 26
  • 48
1 2 3
99
100