str-replace

replace random words in a string

﹥>﹥吖頭↗ 提交于 2019-12-10 11:51:37
问题 I want to create a function that replaces random words in a string. Here is what I thought of. Given a string I would give a random index position within that string. From that index I will replace the nearest word with a word that I want Along with that I would store the word I just replace into some storage variable/database/file Ex. Random word seed: tree, cat, wolf, apple String: The quick brown fox jumps over the lazy dog. Possible Results: The apple brown fox jumps cat the lazy dog. The

Regular expression to remove an iframe

余生颓废 提交于 2019-12-10 10:12:23
问题 I'm trying to use str_replace to replace all iframes with my own content. I believe I can use regular expression but not exactly sure how to remove all content within the iframe tag. Since I'm not really sure how to achieve this, below is what I have been using. But it's only replacing "iframe" with nothing so when a page is loaded anywhere an iframe would load now just shows the URL that would have been loaded if the iframe were to parse properly. $toremove = str_replace("iframe", "",

php str_replace replacing itself

风流意气都作罢 提交于 2019-12-10 05:43:53
问题 I need to replace every occurrence of one of the letters a , o , i , e , u with [aoieu]? I tried to do the following: str_replace(array('a', 'o', 'i', 'e', 'u'), '[aoieu]?', $input); But when giving it input of black instead of giving me the expected bl[aoieu]?ck it gave me bl[a[ao[aoi[aoie[aoieu]?]?[aoieu]?]?[aoie[aoieu]?]?[aoieu]?]?[aoi[aoie[aoieu]?]?[aoieu]?]?[aoie[aoieu]?]?[aoieu]?]?ck How can I get it to not replace things it already replaced? 回答1: You can consider using a regular

Preg_replace/str_replace() for changing `<` and `>` instances to `<` and `>` respectively

China☆狼群 提交于 2019-12-08 08:07:41
问题 One of our pages pulls content from a database table using the following code: <?php echo $project['description']; ?> What I need is for all < and > instances to be replaced with < and > respectively. Can you help modify the above code to include a preg_replace statement (or str_replace() )? 回答1: <?php echo htmlspecialchars_decode($project['description']); ?> Should get you what you need. If you are ONLY looking to decode those, though, then: <?php echo str_replace("<","<",str_replace(">",">"

use preg_replace to replace whole words using associative array

对着背影说爱祢 提交于 2019-12-08 07:53:09
问题 I have this replacement array named $initialdata : array ($initialdata) 'd' => string '1.40' (length=4) 'a' => string '1.67' (length=4) 'vi' => string '0' (length=1) 't' => string '?' (length=1) Then I have this string : $str = "-(vi + sqrt(2*a*d + vi^2))/a)"; When I do : str_replace(array_keys($initialdata),array_values($initialdata),$str); I Get : -(0 + sqr?(2*1.67*1.40 + 0^2))/1.67) What happened was that the "t" of the "sqrt" was replaced by the value of "t" on my $initialdata array. I

How to remove non text chars from string PHP

你。 提交于 2019-12-08 04:03:50
问题 How can I replace chars like 🎧🎬 from a string? Sometime the YouTube video title contains characters like this. I don't want to replace characters like !@#$%^&*(). I am currently using preg_replace('/[^A-Za-z0-9\-]/', '', $VideoTitle); Samples Array: $VideoTitles[]='Sia 2017 Cheap Thrills 2017 live 🎧🎬'; $VideoTitles[]='TAYLOR SWIFT - SHAKE IT OFF 🎬🎧 #1989'; Expected Output: Sia 2017 Cheap Thrills 2017 live TAYLOR SWIFT - SHAKE IT OFF #1989 回答1: Code with sample input: Demo $VideoTitles=[

use preg_replace to replace whole words using associative array

依然范特西╮ 提交于 2019-12-07 13:45:28
I have this replacement array named $initialdata : array ($initialdata) 'd' => string '1.40' (length=4) 'a' => string '1.67' (length=4) 'vi' => string '0' (length=1) 't' => string '?' (length=1) Then I have this string : $str = "-(vi + sqrt(2*a*d + vi^2))/a)"; When I do : str_replace(array_keys($initialdata),array_values($initialdata),$str); I Get : -(0 + sqr?(2*1.67*1.40 + 0^2))/1.67) What happened was that the "t" of the "sqrt" was replaced by the value of "t" on my $initialdata array. I know that this happens because I'm using str_replace , and I need to match whole words using preg_replace

PHP replace string with values from array

断了今生、忘了曾经 提交于 2019-12-07 07:22:09
问题 I have a string such as: Hello <%First Name%> <%Last Name%> welcome and I have a array [0] => Array ( [First Name] => John [Last Name] => Smith ) What I need to do is take the string and replace the words in <% with the actual text from the array So my output would be Hello John Smith welcome Im not sure how to accomplish this but I cant even seem to replace it with regular text $test = str_replace("<%.*%>","test",$textData['text']); Sorry I should of mentioned that the array keys may vary as

Replace multiple characters in a string variable (VBA)

这一生的挚爱 提交于 2019-12-07 06:36:40
问题 How can I replace more than one thing in a string variable? Here my example function in vba: Private Function ExampleFunc(ByVal unitNr$) As String If InStr(unitNr, "OE") > 0 Then unitNr = Replace(unitNr, "OE", "") unitNr = Replace(unitNr, ";", "") End If ... End Function Is there a better solution? 回答1: You could use an array and loop over its elements: Sub MAIN() Dim s As String s = "123456qwerty" junk = Array("q", "w", "e", "r", "t", "y") For Each a In junk s = Replace(s, a, "") Next a

“\\\\”.replaceAll(“\\\\”, “\\”) throws java.lang.StringIndexOutOfBoundsException

与世无争的帅哥 提交于 2019-12-07 01:34:27
问题 The following code fragment in Java: "\\\\".replaceAll("\\\\", "\\"); throws the exception: java.lang.StringIndexOutOfBoundsException: String index out of range: 1 (NO_SOURCE_FILE:0) The javadoc on replaceAll does include a caveat on the use of backslashes and recommends using Matcher.replaceAll or Matcher.quoteReplacement . Does anybody have a snippet on how to replace all occurrences of two backslashes in a string with a single backslash ? clarification The actual literal shown above is