str-replace

Regex str_replace

被刻印的时光 ゝ 提交于 2019-11-28 00:40:20
Would it be possible to incorporate a str_replace method with a regular expression, designed to catch url strings in a simple html < textfield > input type? I'm considering something simple like a tip for the user to set it up as follows: This is some text and click this link here . Obviously the word "here" is a href to the url before it (or after it, if that makes a difference). The text input is drawn from a MySQL db. I believe the start of my solution is something along the lines of: $regex = ''; $pg = $row['pg']; $pg = str_replace('{regex goes here}', $pg); But I know things are missing.

str_replace with array

喜欢而已 提交于 2019-11-28 00:37:53
I'm having some troubles with the PHP function str_replace when using arrays. I have this message: $message = strtolower("L rzzo rwldd ty esp mtdsza'd szdepw ty esp opgtw'd dple"); And I am trying to use str_replace like this: $new_message = str_replace( array('l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k'), array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'), $message); The result should be A good glass in the bishop's hostel in the devil's seat , but instead, I get p voos vlpss

Remove Unicode Zero Width Space PHP

六月ゝ 毕业季﹏ 提交于 2019-11-28 00:24:41
问题 I have a text in Burmese language, UTF-8. I am using PHP to work with the text. At some point along the way, some ZWSPs have crept in and I would like to remove them. I have tried two different ways of removing the characters, and neither seems to work. First I have tried to use: $newBody = str_replace("​", "", $newBody); to search for the HTML entity and remove it, as this is how it appears under Web Inspector. The spaces don't get removed. I have also tried it as: $newBody = str_replace("&

How to replace multiple items from a text string in PHP? [duplicate]

妖精的绣舞 提交于 2019-11-27 18:58:13
This question already has an answer here: How do I replace certain parts of my string? 5 answers I want to be able to replace spaces with - but also want to remove commas and question marks. How can I do this in one function? So far, I have it replacing spaces: str_replace(" ","-",$title) You can pass arrays as parameters to str_replace() . Check the manual . // Provides: You should eat pizza, beer, and ice cream every day $phrase = "You should eat fruits, vegetables, and fiber every day."; $healthy = ["fruits", "vegetables", "fiber"]; $yummy = ["pizza", "beer", "ice cream"]; $newPhrase = str

PHP preg_replace/preg_match vs PHP str_replace

北慕城南 提交于 2019-11-27 18:08:53
Can anyone give me a quick summary of the differences please? To my mind they both do the same thing? Thanks str_replace replaces a specific occurrence of a string, for instance "foo" will only match and replace that: "foo". preg_replace will do regular expression matching, for instance "/f.{2}/" will match and replace "foo", but also "fey", "fir", "fox", "f12", etc. [EDIT] See for yourself: $string = "foo fighters"; $str_replace = str_replace('foo','bar',$string); $preg_replace = preg_replace('/f.{2}/','bar',$string); echo 'str_replace: ' . $str_replace . ', preg_replace: ' . $preg_replace;

How to remove accents and tilde in a C++ std::string

风流意气都作罢 提交于 2019-11-27 16:12:19
问题 I have a problem with a string in C++ which has several words in Spanish. This means that I have a lot of words with accents and tildes. I want to replace them for their not accented counterparts. Example: I want to replace this word: "había" for habia. I tried replace it directly but with replace method of string class but I could not get that to work. I'm using this code: for (it= dictionary.begin(); it != dictionary.end(); it++) { strMine=(it->first); found=toReplace.find_first_of(strMine)

How can I perform a str_replace in JavaScript, replacing text in JavaScript?

一曲冷凌霜 提交于 2019-11-27 11:16:03
I want to use str_replace or its similar alternative to replace some text in JavaScript. var text = "this is some sample text that i want to replace"; var new_text = replace_in_javascript("want", "dont want", text); document.write("new_text"); should give this is some sample text that i dont want to replace If you are going to regex, what are the performance implications in comparison to the built in replacement methods. Using regex for string replacement is significantly slower than using a string replace. As demonstrated on JSPerf , you can have different levels of efficiency for creating a

Trying to replace parts of string start with same search chars

偶尔善良 提交于 2019-11-27 09:54:13
I'm trying to replace parts of my string. But I met a problem when my search string start with same character: $string = "Good one :y. Keep going :y2"; $str = str_replace(array_keys($my_array), array_values($my_array), $string); $my_array= array(":y" => "a", ":y2" => "b"); ouput: Good one a. Keep going a2 I need my str_replace() to match the word correctly/exactly. Besides that you should define your array first before you use it, this should work for you: $str = strtr($string, $my_array); Your problem is that str_replace() goes through the entire string and replaces everything it can, you can

How to replace a letter in a string with a new letter that will not be updated

风格不统一 提交于 2019-11-27 08:25:00
问题 Lets say I have some code: $text = $_POST['secret']; $replaces = array( 'a' => 's', 'b' => 'n', 'c' => 'v', 'd' => 'f', 'e' => 'r', 'f' => 'g', 'g' => 'h', 'h' => 'j', 'i' => 'o', 'j' => 'k', 'k' => 'l', 'l' => 'a', 'm' => 'z', 'n' => 'm', 'o' => 'p', 'p' => 'q', 'q' => 'w', 'r' => 't', 's' => 'd', 't' => 'y', 'u' => 'i', 'v' => 'b', 'w' => 'e', 'x' => 'c', 'y' => 'u', 'z' => 'x', ); $text = str_replace(array_keys($replaces),array_values($replaces),$text); echo "You're deciphered message is:

Simple: How to replace “all between” with php? [duplicate]

别等时光非礼了梦想. 提交于 2019-11-27 06:36:39
问题 This question already has answers here : How to remove text between tags in php? (6 answers) Closed 6 days ago . $string = "<tag>i dont know what is here</tag>" $string = str_replace("???", "<tag></tag>", $string); echo $string; // <tag></tag> So what code am i looking for? 回答1: $search = "/[^<tag>](.*)[^<\/tag>]/"; $replace = "your new inner text"; $string = "<tag>i dont know what is here</tag>"; echo preg_replace($search,$replace,$string); outputs: <tag>your new inner text</tag> 回答2: A