str-replace

PHP String Replace between two html tags

自古美人都是妖i 提交于 2019-12-25 02:24:43
问题 I am trying to replace text between two tags in a html document. I want to replace any text that isn't enclosed with a < and >. I want to use str_replace to do this. php $string = '<html><h1> some text i want to replace</h1><p>some stuff i want to replace </p>'; $text_to_echo = str_replace("Bla","Da",$String); echo $text_to_echo; 回答1: Try this: <?php $string = '<html><h1> some text i want to replace</h1><p> some stuff i want to replace </p>'; $text_to_echo = preg_replace_callback( "/(<([^.]+)

Simple HTML DOM str_replace on plain text

拥有回忆 提交于 2019-12-25 02:09:59
问题 I am trying to create something where it will change all of the text on a webpage and re output it to the user. It will be changing words predefined in a database. I am using http://simplehtmldom.sourceforge.net as my HTML parser. What i want todo is to change only the test inside of tags but not the tags. I thought this would work, If i echo out $e->plaintext it will work but then it isn't styled. <?php // example of how to modify HTML contents include('../simple_html_dom.php'); // get DOM

PHP - Issues removing “\r\n\r\n” from this string: “I would like to:\r\n\r\n1.) Rid this mess\r\n\r\n\2.) Now Please”

我与影子孤独终老i 提交于 2019-12-24 10:48:55
问题 I start out with a string like this : "I would like to:\r\n\r\n1.) Rid this mess\r\n\r\n\2.) Now Please" (this is 'cleaned' user input text). So essentially my statement would be this : $query = sanitize($_POST['query']); // gives the result string I want to remove the "\r\n\r\n"'s from this string. So far I have try to do this by using the following : $query = preg_replace("/\r\n\r\n/", " ", $query); or $query = str_replace("\r\n\r\n", " ", $query); None seem to work? However, if I do the

php string replace quotes

﹥>﹥吖頭↗ 提交于 2019-12-24 09:43:42
问题 Hello I am trying to get all single quotes to be double quotes using the php str_replace however it does not seem to be working no matter what I do, suggestions $page = str_replace("/'/", '/"/', $page); 回答1: Update: I'd agree with others that the following is an easier-to-read alternative for most folks: $page = str_replace("'", '"', $page); My original answer: $page = str_replace(chr(39), chr(34), $page); 回答2: You don't need to escape the quote character (in fact it is \ , not / , unless you

Str_replace with regex

99封情书 提交于 2019-12-24 07:28:11
问题 Say I have the following link: <li class="hook"> <a href="i_have_underscores">I_have_underscores</a> </li> How would I, remove the underscores only in the text and not the href? I have used str_replace, but this removes all underscores, which isn't ideal. So basically I would be left with this output: <li class="hook"> <a href="i_have_underscores">I have underscores</a> </li> Any help, much appreciated 回答1: It's safer to parse HTML with DOMDocument instead of regex. Try this code: <?php

outputting \r\n after text is decoded - PHP

半城伤御伤魂 提交于 2019-12-24 06:41:57
问题 I am building an application where users can enter a note into a textarea. The note is then encoded when entered into the database. When I decode the returned value, the nl2br function isn't working. It isn't replacing the \r\n with the br tag. When not encoding/decoding text, it works. I am using the following code to encode/decode my information: http://www.myphpscripts.net/tutorial.php?id=9 If I enter into a textarea: Hello World It encodes it, and then returns when decoded Hello\r\nWorld.

Could you tell how to replace by regular expression

久未见 提交于 2019-12-24 05:11:29
问题 Could you tell how to replace string by preg-replace (need regular expression): /user/{parent_id}/{action}/step/1 At the equivalent values of an array: array('parent_id'=>32, 'action'=>'some'); To make: /user/32/some/step/1 Addition This is a typical problem, so I probably will not know what the names of variables come 回答1: $arr = array('parent_id'=>32, 'action'=>'some'); $out = str_replace(array_keys($arr),array_values($arr),$in); no need for regexps! 回答2: You can use str_replace For example

str_replace text with image

雨燕双飞 提交于 2019-12-24 04:14:05
问题 I have a chat box and would like to replace things such as ' :D ' with an icon. $chatText = str_replace(":D","<img src='images/icons/smileys/smile-big.png' width='20' height='20' alt='Big Smile' />",$chatText); Above is the code I'm using. On the chat, instead of replacing text with emotions, it literally replaces the ":D" with the html code: <img src='images/icons/smileys/smile-big.png' width='20' height='20' alt='Big Smile' /> I have made a few attempts at changes (that I've researched)

replace multiple sub-strings in a string

。_饼干妹妹 提交于 2019-12-24 00:54:46
问题 This function is used to replace certain substrings in a string with respective values. // map(string_to_replace, string_to_replace_with) String template = "ola ala kala pala sala"; StringBuilder populatedTemplate = new StringBuilder(); HashMap<String, String> map = new HashMap<>(); map.put("ola", "patola"); map.put("pala", "papala"); int i=0; for (String word : template.split("'")) { populatedTemplate.append( map.getOrDefault(word, word)); populatedTemplate.append(" "); } System.out.println

PHP preg_match to find relevant word

笑着哭i 提交于 2019-12-24 00:03:32
问题 I have a variable with value like this : $sentence = "When it comes time to renew your auto insurance policy, be aware of how your carrier handles renewals"; And I have array variables with value below : $searches = array('aware', 'aware of', 'be aware', 'be aware of'); $replaces = array('conscious', 'conscious of', 'remember', 'concentrate on'); I would like to find just 'be aware of' and then replace with 'concentrate on'. Output like below : When it comes time to renew your auto insurance