Search the Community
Showing results for tags 'replace'.
-
Basically I have a very long form select option drop down list. What I would like to do is that for each option "value", I want to remove the spaces and instead add dash to it. Doing each option value by hand would take me a very long time, so I thought I might try jquery for short cut. If you have another method, let me know. Here's what I have so far. Doesn't seem to work. <script> $(document).ready(function () { $('#model').change(function(){ var str = $(this).val(); str = str.replace(/\s+/g, "-"); }); }); </script> // here's an example of select options <select id="model" name="model"> <option value="john doe" >John Doe</option> <option value="john smith lu" >John Smith Lu</option> </select>
- 10 replies
-
- remove spaces
- replace
-
(and 3 more)
Tagged with:
-
I have created a word game in php/mysql where users are presented with a randomly selected word in a foreign language and then have to fill in missing letters (which depending on the word length are sometimes randomly removed or sometimes all letters are removed) from the english version of these words into form input fields which are later submitted to the database via a form for checking... The code below works ok except for when a word has more than one instance of a particular letter for examples the word "Bees" For example it will go through find "e" but then replace both instances of the letter "e" with either <input type="text" name="question_1_letter_1" class="inputs" maxlength="1" value="" /> or <input type="text" name="question_1_letter_2" class="inputs" maxlength="1" value="" /> What I really want to happen is for it to just replace once the first "e" it finds so one instance of the letter "e" is replaced by <input type="text" name="question_1_letter_1" class="inputs" maxlength="1" value="" /> and the other instance is replaced with <input type="text" name="question_1_letter_2" class="inputs" maxlength="1" value="" /> here is the main code $one = "question_1_letter_$key1"; $two = "question_1_letter_$key2"; $three = "question_1_letter_$key3"; $four = "question_1_letter_$key4"; $string = Bees; $selected_letter1 = B; $selected_letter2 = e; $selected_letter3 = e; $selected_letter4 = s; $Find = Array($selected_letter1, $selected_letter2, $selected_letter3, $selected_letter4); $Replace = Array( "`<input type=\"text\" name=\"$one\" class=\"inputs\" maxlength=\"1\" value=\"\" />`", "`<input type=\"text\" name=\"$two\" class=\"inputs\" maxlength=\"1\" value=\"\" />`", "`<input type=\"text\" name=\"$three\" class=\"inputs\" maxlength=\"1\" value=\"\" />`", "`<input type=\"text\" name=\"$four\" class=\"inputs\" maxlength=\"1\" value=\"\" />`" ); $New_string = strtr($string, array_combine($Find, $Replace)); echo $New_string; Hope that makes sense! Im still very much a novice php programmer and stuck as to how I can achieve this and may well be overlooking a much simpler solution that I am currently unaware of... if anyone can lend a hand and give me some pointers it would be greatly appreciated!!
-
The situation is that I have a large string with some identifiers to say "replace me" with something else. My goal is to replace the values, but if one replacement includes one of the other keys, I don't want to replace it. For example: <?php $str = 'some blob ~abc~ followed by ~def~'; $arr_orig = array( '~abc~', '~def~' ); $arr_new = array( 'value~def~', 'blah' ); echo str_replace( $arr_orig, $arr_new, $str ); ?> This will echo: some blob valueblah followed by blah But that's not what I'm trying to accomplish. Basically, I want ~abc~ to be replaced with the literal: value~def~ and for the ~def~ that happens to be part of that string to NOT be replaced. I hope what I'm asking is clear. Basically, preg_replace/str_replace with arrays seems no different than just doing a FOR loop and replacing ~abc~ and then ~def~. But that's not what I need. I'm hoping that if ~abc~ is replaced with text that happens to be another identifier -- ~def~, ~xyz~, whatever -- that this already replaced text is not again replaced. Is there a built-in function to do something like this? If not, should I just parse the whole string and count characters or something? Seems like a pain (and slow!)
-
I want to replace key words from an array in a user input string for all instances and case insensitive with the string "NOPE". An example array would be... var replacer = new Array("@", "$", "*", "drip", "slide", "move", "(", "\)"); Example: var userInput = "I have to slide down @ $3.00 with all (*) of the $ and moVe to another driping SLIDe"; *Magic replacement...* var output = "I have to NOPE down NOPE NOPE3.00 with all NOPENOPENOPE of the NOPE and NOPE to another NOPEing NOPE"; How would I do that?
-
I just found code that does this: orig = orig.replace( "<br>", "<br>" ); orig = orig.replace( "<BR>", "<br>" ); orig = orig.replace( "<bR>", "<br>" ); orig = orig.replace( "<Br>", "<br>" ); I see why it's done this way (to encompass any caps variation on the BR) but since .replace() will only get the first instance, this is just bad all the way around. Also, there's no way to do a toLowerCase() because that will mess up the rest of the string. Is there some sort of JS regex way to replace all instances of <br> regardless of the caps? Thanks!
- 1 reply
-
- javascript
- string
-
(and 1 more)
Tagged with:
-
This code should be pretty self explanatory, but I'm struggling bad to get it to work. I want to check if the "propview" element is blank, if so, replace it with "No Contingencies". Simple right? $details_array = array( "propview" => JText::_('COM_IPROPERTY_PROPVIEW' ), "beds" => JText::_('COM_IPROPERTY_BEDS' ), "baths" => JText::_('COM_IPROPERTY_BATHS' ), "sqft" => (!$this->settings->measurement_units) ? JText::_('COM_IPROPERTY_SQFT' ) : JText::_('COM_IPROPERTY_SQM' ), "lotsize" => JText::_('COM_IPROPERTY_LOT_SIZE' ), "lot_acres" => JText::_('COM_IPROPERTY_LOT_ACRES' ), "yearbuilt" => JText::_('COM_IPROPERTY_YEAR_BUILT' ), "heat" => JText::_('COM_IPROPERTY_HEAT' ), "garage_type" => JText::_('COM_IPROPERTY_GARAGE_TYPE' ), "roof" => JText::_('COM_IPROPERTY_ROOF' )); if(empty($details_array["propview"])) { $details_array = array( "propview" => "No Contingencies" ); } It either doesn't do anything or it wipes out the entire array. Maybe the logic should be embedded in the original array, but I haven't found any examples that show that ever being done.
-
Hi, PHP geniuses. I am a PHP novice and am stuck. For someone knowledgeable, this should be pretty easy, but it is stumping me. I have a site that is multiple languages. The only difference in the pages from one language to the next is a "/it/" at the end of the main url before the page name. I need 2 inline PHP statements that create hrefs: One that creates a link that says "remove 'it/' from the current page URL One that takes the current url and ads a 'it/" after the domain name and before the page name in a link. Example: If the current page URL is http://www.xxx.com/it/test/ - it creates a link that is http://www.xxx.com/test/ The second piece of code creates a link that changes http://www.xxx.com/test/ to http://www.xxx.com/it/test/ I have played with some PHP string replace commands, but I can't get it to work. I need something like: <a href='<?php echo str_replace ("/it/",""; ?>'> Anyway, bad code example, but you get the idea. Anyone know a quick fix here?
-
I have a question to use regex in PHP. i have a string in murkup.and wanna to convert it to html. These are my strings: 1. "Text Link":http://site.com It want to be a html link with url after : and before "space" at the end, and link's text is string between the quotations 2. !http://site.com/picture.gif! It want to be a html img tag: <img src='link between "!" characters' /> 3. *.my text It want to be an item in html tag : <li>mytext after "*." and before "enter" (new line)</li> or etc. how can i do it? i try many solutions in regex but not worked right. Thanks