str-replace

Quickest way to replace a series of characters in a string

岁酱吖の 提交于 2019-12-11 11:57:35
问题 I'm wondering what is the quickest way to replace certain characters in a string with nothing. I now have the following: $omschrijving = str_replace(")", "", str_replace("(", "", $line))); Is there a better way to do this? This is only replacing the "(" and ")" , but what if I want to do the same with more characters. Still learning the preg_ methods but it's still a bit of mind blowing at the moment. 回答1: Here you go: str_replace(array('a', 'b', 'c', 'd'), '', $sString); From the manual: The

“Get” function doesn't work because not all hyphens should be replaced

[亡魂溺海] 提交于 2019-12-11 10:37:28
问题 I use a Get function to look for the field model in an url but I have a problem when the model contains a space and a hyphen. Example: my model in the url is " this-f-example " and the model in the database is " this f-example " (so without the first hyphen). I wrote the following php code, but it's not sufficient. It would only look for this f example or this-f-example in my database so it would return nothing because those models don't exist. What should I change to my code so it would look

Unrecognized Character Between Empty P Tags TinyMCE

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 09:26:42
问题 What character does tinyMCE put in between empty p tags. I have the following empty p tags: <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> Which I'd like to remove... but they are not recognized by str_replace or preg_replace. The best I could do to track down the issue, is the space between the tags. In other words I can remove the <p> by itself or the </p> ... but when I try searching for <p> </p> it doesn't find it. Tried   or I found many solutions online but NONE work. It seems

PHP editing Microsoft Word document str_replace and preg_replace don't work

你。 提交于 2019-12-11 03:44:03
问题 Assume, I've got MSWord file source.doc with next content "Content of Microsoft Word file". For example, I'd like to open it via PHP and replace word "Microsoft" to "Openoffice" and save the result into result.doc . Here is the code using preg_replace : $content = file_get_contents( SOMEPATH . '/source.doc' ); $new_content = preg_replace( '/Microsoft/i', 'Openoffice', $content ); file_put_contents( SOMEPATH . '/target.doc', $new_content ); Or using str_replace : $content = file_get_contents(

str_replace not replacing special chars

流过昼夜 提交于 2019-12-11 02:46:35
问题 In a project of mine, I'm having a few upload forms. Since I live in Sweden, I want to encode the Swedish special characters to their respective HTML-code, so that encoding won't be an issue when displaying the data. Here's the code: function format_text($text){ $chars = ['å','ä','ö','Å','Ä','Ö']; $codes = ['å','ä','ö','&Aring','Ä','Ö']; foreach($chars as $key => $value){ $text = str_replace($value,$codes[$key],$text); } $text = str_replace("\r","\n",$text); $text = preg_replace("!\n\n+!", "

How to replace last comma in string with “and” using php?

☆樱花仙子☆ 提交于 2019-12-11 01:19:30
问题 I'm trying to replace the last occurence of a comma in a text with "and" using strrchr() and str_replace() . Example: $likes = 'Apple, Samsung, Microsoft'; $likes = str_replace(strrchr($likes, ','), ' and ', $likes); But this replaces the entire last word (Microsoft in this case) including the last comma in this string. How can I just remove the last comma and replace it with " and " ? I need to solve this using strrchr() as a function. That's why this question is no duplicate and more

Replace multiple occurrences of a string with different values

青春壹個敷衍的年華 提交于 2019-12-10 20:35:51
问题 I have a script that generates content containing certain tokens, and I need to replace each occurrence of a token, with different content resulting from a separate loop. It's simple to use str_replace to replace all occurrences of the token with the same content, but I need to replace each occurrence with the next result of the loop. I did see this answer: Search and replace multiple values with multiple/different values in PHP5? however it is working from pre-defined arrays, which I don't

replace entites in rawurlencode i.e. < > "

狂风中的少年 提交于 2019-12-10 15:28:42
问题 I have the following code <a href="snippet:add?code=<?php echo rawurlencode($snippet->snippet_content); ?>Save snippet</a> where '$snippet = <a rel="nofollow" href="http://digg.com/submit?phase=2&url=<?php the_permalink(); ?>" title="Submit this post to Digg">Digg this!</a>' How could I get rawurlencode to replace "&lt"; to a "<"? Many thanks in advance rob updated using <?php echo rawurlencode(html_entity_decode($snippet->snippet_content)); ?> as suggested by the posters below, thankyou

How to str_replace a section of PHP Code

故事扮演 提交于 2019-12-10 12:28:26
问题 $embedCode = <<<EOF getApplicationContent('video','player',array('id' => $iFileId, 'user' => $this->iViewer, 'password' => clear_xss($_COOKIE['memberPassword'])),true) EOF; $name = str_replace($embedCode,"test",$content); I'm trying to replace a section of code with another piece of code. I can do it with smaller strings but once I added the larger strings to $embedCode, it throw an "unexpected T_ENCAPSED_AND_WHITESPACE" error 回答1: you should unescape the $ using \$ $embedCode = <<<EOF

Replace unicode value in string

雨燕双飞 提交于 2019-12-10 12:17:48
问题 I have a string @"\EOP" . I want to dislpay this to user. But when i display this string in textfield, It shows only OP . I tried to print that in console while debugging and it shows ¿OP So \E is unicode value and that's why it's having some issue of encoding. I can fix this issue by: NSString *str=[str stringByReplacingOccurrencesOfString:@"\E" withString:@"\\E"]; With this it will display perfect string @"\EOP" . Here my issue is that there can be many more characters same like \E for