Search Results

Search found 9872 results on 395 pages for 'preg replace callback'.

Page 66/395 | < Previous Page | 62 63 64 65 66 67 68 69 70 71 72 73  | Next Page >

  • Replace duplicate values in array with new randomly generated values

    - by RussellDias
    I have below a function (created by Gordon in a previous question that went unanswered) that creates an array with n amount of values. The sum of the array is equal to $max. function randomDistinctPartition($n, $max) { $partition= array(); for($i=1; $i < $n; $i++) { $maxSingleNumber = $max - $n; $partition[] = $number = rand(1, $maxSingleNumber); } $max -= $number; } $partition[] = $max; return $partition; } For example: If I set $n = 4 and $max = 30. Then I should get the following. array(5, 7, 10, 8); However, this function does not take into account duplicates and 0s. What I would like - and have been trying to accomplish - is to generate an array with unique numbers that add up to my predetermined variable $max. No Duplicate numbers and No 0 and/or negative integers.

    Read the article

  • How to search and replace an unprintable character

    - by krzyk
    I've a file that was exported from Word and it replaced all quotes with strange unicode characters which aren't correctly displayed in vim. So now I want those characters to be replaced with quotes, but I don't know how to enter this character in :%s/???/'/g The characters look like this: ~U ~R. But of course I can't just mark them with mouse and paste in the command.

    Read the article

  • What is the accepted way to replace java.util.Date(year,month,day)

    - by dagw
    I'm trying to do something really simple, but starting to realize that dates in Java are a bit of minefield. All I want is to get passed groups of three ints ( a year, a month and a date) create some Date objects, do some simple test on them (along the lines of as date A before date B and after January 1 1990), convert them to java.sql.Date objects and pass them off to the database via JDBC. All very simple and works fine using the java.util.Date(int year,int month,int day) constructor. Of course that constructor is depreciated, and I'd like to avoid using depreciated calls in new code I'm writing. However all the other options to solve this simple problem seem stupidly complicated. Is there really no simple way to do what I want without using depreciated constructors? I know the standard answer to all Java date related questions is "use joda time", but I really don't want to start pulling in third party libraries for such a seemingly trivial problem.

    Read the article

  • Replace a DIV with another using effect and set cookie

    - by Alex
    Hi. I've got some complicated requirements and wondered if there's a way to accomplish this via jQuery: User comes to a web page for the first time today and we show DIV_1. After 30 seconds, we dissolve DIV_1 to DIV_2. We set a cookie on the user's machine that expires when s/he returns tomorrow. If the same user returns today, we only show DIV_2. Tomorrow, we repeat the process: The user will see DIV_1 and then it dissolves to DIV_2. How do you accomplish this via jQuery? Thank you.

    Read the article

  • Using a large list of terms, search through page text and replace words with links

    - by dunc
    A while ago I posted this question asking if it's possible to convert text to HTML links if they match a list of terms from my database. I have a fairly huge list of terms - around 6000. The accepted answer on that question was superb, but having never used XPath, I was at a loss when problems started occurring. At one point, after fiddling with code, I somehow managed to add over 40,000 random characters to our database - the majority of which required manual removal. Since then I've lost faith in that idea and the more simple PHP solutions simply weren't efficient enough to deal with the amount of data and the quantity of terms. My next attempt at a solution is to write a JS script which, once the page has loaded, retrieves the terms and matches them against the text on a page. This answer has an idea which I'd like to attempt. I would use AJAX to retrieve the terms from the database, to build an object such as this: var words = [ { word: 'Something', link: 'http://www.something.com' }, { word: 'Something Else', link: 'http://www.something.com/else' } ]; When the object has been built, I'd use this kind of code: //for each array element $.each(words, function() { //store it ("this" is gonna become the dom element in the next function) var search = this; $('.message').each( function() { //if it's exactly the same if ($(this).text() === search.word) { //do your magic tricks $(this).html('<a href="' + search.link + '">' + search.link + '</a>'); } } ); } ); Now, at first sight, there is a major issue here: with 6,000 terms, will this code be in any way efficient enough to do what I'm trying to do?. One option would possibly be to perform some of the overhead within the PHP script that the AJAX communicates with. For instance, I could send the ID of the post and then the PHP script could use SQL statements to retrieve all of the information from the post and match it against all 6,000 terms.. then the return call to the JavaScript could simply be the matching terms, which would significantly reduce the number of matches the above jQuery would make (around 50 at most). I have no problem with the script taking a few seconds to "load" on the user's browser, as long as it isn't impacting their CPU usage or anything like that. So, two questions in one: Can I make this work? What steps can I take to make it as efficient as possible? Thanks in advance,

    Read the article

  • Replace an element name while retaining the attributes with jquery

    - by geckomist
    I'm trying to create a jquery setup where all instances of <i> are changed to <em>. It's easy enough to do with: $("i").each(function(){ $(this).replaceWith($('<em>' + this.innerHTML + '</em>')); }); But what I am having trouble figuring out is how to change all the <i> tags but retain each ones individual attributes. So if I have <i style="background-color: #333;" alt="Example" title="Example">Example Text</i> I would like it to change to <em style="background-color: #333;" alt="Example" title="Example">Example Text</em> Thanks for any help!

    Read the article

  • Faster Javascript text replace

    - by Stacey
    Given the following javascript (jquery) $("#username").keyup(function () { selected.username = $("#username").val(); var url = selected.protocol + (selected.prepend == true ? selected.username : selected.url) + "/" + (selected.prepend == true ? selected.url : selected.username); $("#identifier").val(url); }); This code basically reads a textbox (username), and when it is typed into, it reconstructs the url that is being displayed in another textbox (identifier). This works fine - there are no problems with its functionality. However it feels 'slow' and 'sluggish'. Is there a cleaner/faster way to accomplish this task? Here is the HTML as requested. <fieldset class="identifier delta"> <form action="/authenticate/openid" method="post" target="_top" > <input type="text" class="openid" id="identifier" name="identifier" readonly="readonly" /> <input type='text' id='username' name='username' class="left" style='display: none;'/> <input type="submit" value="Login" style="height: 32px; padding-top: 1px; margin-right: 0px;" class="login right" /> </form> </fieldset> The identifier textbox just has a value set based on the hyperlink anchor of a button.

    Read the article

  • jQuery table replace

    - by Happy
    We have a table: <table> <tr> <td width="10">1</td> <td>text 1</td> </tr> <tr> <td width="10">2</td> <td>text 2</td> </tr> <tr> <td width="10">3</td> <td>text 3</td> </tr> <tr> <td width="10">4</td> <td>text 4</td> </tr> <tr> <td width="10">5</td> <td>text 5</td> </tr> <tr> <td width="10">6</td> <td>text 6</td> </tr> <tr> <td width="10">7</td> <td>text 7</td> </tr> <tr> <td width="10">8</td> <td>text 8</td> </tr> <tr> <td width="10">9</td> <td>text 9</td> </tr> <tr> <td width="10">10</td> <td>text 10</td> </tr> </table> We update this table by throwing into each <tr> 3 <td>, each <td> with width="10" attribute must be deleted. It must look like: <table> <tr> <td>text 1</td> <td>text 2</td> <td>text 3</td> </tr> <tr> <td>text 4</td> <td>text 5</td> <td>text 6</td> </tr> <tr> <td>text 7</td> <td>text 8</td> <td>text 9</td> </tr> <tr> <td>text 10</td> </tr> </table> How can we do this? Thanks.

    Read the article

  • find and replace values in csv using PHP

    - by peirix
    I'd think there was a question on this already, but I can't find one. Maybe the solution is too easy... Anyway, I have a csv and want to let the user change the values based on a name. I've already sorted out creating new name+value-pairs using the fopen('a') mode, using jQuery to send the AJAX call with newValue and newName. But say the content looks like this: host|http:www.stackoverflow.com folder|/questions/ folder2|/users/ And now I want to change the folder value. So I'll send in folder as oldName and /tags/ as newValue. What's the best way to overwrite the value? The order in the list doesn't matter, and the name will always be on the left, followed by a |(pipe), the value and then a new-line. My first thought was to read the list, store it in an array, search all the [0]'s for oldName, then change the [1] that belongs to it, and then write it back to a file. But I feel there is a better way around this? Any ideas? Maybe regex?

    Read the article

  • C++: static function member shared between threads, can block all?

    - by mhambra
    Hi all, I have a class, which has static function defined to work with C-style extern C { static void callback(foo bar) { } }. // static is defined in header. Three objects (each in separate pthread) are instantiated from this class, each of them has own loop (in class constructor), which can receive the callback. The pointer to function is passed as: x = init_function(h, queue_id, &callback, NULL); while(1) { loop_function(x); } So each thread has the same pointer to &callback. Callback function can block for minutes. Each thread object, excluding the one which got the blocking callback, can call callback again. If the callback function exists only once, then any thread attempting to callback will also block. This would give me an undesired bug, circa is interesting to ask: can anything in C++ become acting this way? Maybe, due to extern { } or some pointer usage?

    Read the article

  • case insenstive string replace that correctly works with ligatures like "ß" <=> "ss"

    - by usr
    I have build a litte asp.net form that searches for something and displays the results. I want to highlight the search string within the search results. Example: Query: "p" Results: a<b>p</b>ple, banana, <b>p</b>lum The code that I have goes like this: public static string HighlightSubstring(string text, string substring) { var index = text.IndexOf(substring, StringComparison.CurrentCultureIgnoreCase); if(index == -1) return HttpUtility.HtmlEncode(text); string p0, p1, p2; text.SplitAt(index, index + substring.Length, out p0, out p1, out p2); return HttpUtility.HtmlEncode(p0) + "<b>" + HttpUtility.HtmlEncode(p1) + "</b>" + HttpUtility.HtmlEncode(p2); } I mostly works but try it for example with HighlightSubstring("ß", "ss"). This crashes because in Germany "ß" and "ss" are considered to be equal by the IndexOf method, but they have different length! Now that would be ok if there was a way to find out how long the match in "text" is. Remember that this length can be != substring.Length. So how do I find out the length of the match that IndexOf produces in the presence of ligatures and exotic language characters (ligatures in this case)?

    Read the article

  • Search and replace in apache htaccess a RewriteRule

    - by Paul Irish
    I'd basically like to get /path/file+name+with+plusses.mp3 to rewrite to /path/file name with plusses.mp3 In my case wordpress is intercepting the request and giving a 404. But the file does indeed exist. Given the constraints of the regex in mod_rewrite implementation, I haven't yet seen a straightforward way of doing this.

    Read the article

  • Simple Search and Replace use of Regular Expression

    - by nunos
    So, I am adapting some code I found online to suit my needs. However, my set_pixel function has two more parameters. Since there are lots of calls to this function even doing a quick paste over would be very tedious. So, I thought this would be a good time for me to learn some simple regular expressions. So, I have calls of this type: set_pixel(arg1, arg2); which I want to change to something like: set_pixel(arg1, arg2, arg3, arg4); Note: arg1 and and 2 should be preserved, whereas arg3 and arg4 are most of the time the same. How can I achieve this?

    Read the article

  • Replace occurance of character with all letters in the alphabet

    - by McAvoy
    I have created a scrabble game with a computer opponent. If a blank tile is found in the computer's rack during the word generation if needs to be swapped out for every letter in the alphabet. I have my current solution to solve this problem below, but was wondering if there is a better more efficient way to accomplish this task. if (str.Contains("*")) { char c = 'A'; String made = ""; while(c < 'Z') { made = str.ReplaceFirst("*", c.ToString()); if (!made.Contains("*")) { wordsMade.Add(made); if (theGame.theTrie.Search(made) == Trie.SearchResults.Found) { validWords.Add(made); } } else { char ch = 'A'; String made2 = ""; while (ch < 'Z') { made2 = made.ReplaceFirst("*", c.ToString()); wordsMade.Add(made2); if (theGame.theTrie.Search(made2) == Trie.SearchResults.Found) { validWords.Add(made2); } ch++; } } c++; }

    Read the article

  • Notepad++ regular expression find and replace $_REQUEST with $_GET but a more secure

    - by David
    What I am doing is replacing, in a large program, all $_REQUEST['var'] and mysql_escape_string($_REQUEST['var']) with either the 1st or 2nd line below the dotted line. Now, I have figured out this much of the regular expression but I would like to make it simpler. Instead of having to run the top one first then the 2nd one I would like to just run one all together. I tried this but it did not work. (mysql_escape_string\()*$_REQUEST\[\'([^']*)\'\]\)(\)*) So below is what works but again have to do it twice. $_REQUEST\[\'([^']*)\'\] mysql_escape_string\($_REQUEST\[\'([^']*)\'\]\) (isset($_GET['\1'])?mysql_real_escape_string($_GET['\1']):false) (isset($_POST['\1'])?mysql_real_escape_string($_POST['\1']):false) ============================ Update: Yeah, after some research I figured out that Notepad++ does not support most regular expressions. I guess one additional step can not hurt a person. It's just laziness. *NOTE: BUT if anyone wants to try feel free to comment. At least it is just 2 steps and not 20.

    Read the article

  • Replace data in MySQL table with data from another table

    - by Oli
    I am trying to modify an existing MySQL database for use in a new application. I have a table of items (table_items), which has multiple fields, including "ItemID" and "ItemName". I have another table (table_list) which has "ItemName" in it, but no ItemID. I need to either update this table to contain ItemID instead of ItemName, or create a new table which imports ItemIDs from table_items as opposed to the ItemName when table_list.ItemName = table_items.ItemName. I have tried the following: UPDATE table_list A, table_items B SET A.ItemName = B.ItemID WHERE A.ItemName = B.ItemName The current table has over 500,000 rows and every time i try this in PHPMyAdmin i get the error "the MySQl server has gone away". Any help greatly appreciated.

    Read the article

  • Replace Emails and HREFS with enclosing HREFS in C#

    - by Nissan Fan
    I have an Email body that used to be plain text, but now I've made it HTML. The emails are generated using a number of methods and none of them are easy to convert. What I have is: Some content [email protected], some http://www.somewebsite/someurl.aspx. What I'd like to do is create a function that automatically encloses all email addresses and all URLs withing a string in HREF tags so that the HTML email reads properly in all email clients. Does anyone have a function for this?

    Read the article

  • SQL update statement to change the value of a field and not replace it

    - by wzzrd
    I'm in the process of migrating some databases. I have this table that has a couple of hundred rows, and has a filename column. To each record in this table, the filename column needs to be altered and part of a path needs to be prepended to the value that is in that field. The table is like: | 1 | filename1 | | 2 | filename2 | and needs to become: | 1 | path/filename1 | | 2 | path/filename2 | I am not an SQL guru, but I know the basics. This eludes me though. Is there a way to do something like: update table set filename = 'path/' + filename where id = 1;

    Read the article

  • Wherewith replace Dictionary.Where(p => p.Key is T)

    - by abatishchev
    I have a System.Collections.Generic.Dictionary<System.Web.UI.Control, object> where all keys can be either type of System.Web.UI.WebControls.HyperLink or type of System.Web.UI.WebControls.Label. I want to change Text property of each control. Because HyperLink doesn't implement (why??) ITextControl, I need to cast Label or HyperLink explicitly: Dictionary<Control,object> dic = .. dic .Where(p => p.Key is HyperLink) .ForEach(c => ((HyperLink)c).Text = "something") dic .Where(p => p.Key is Label) .ForEach(c => ((Label)c).Text = "something") Are there ways to workaround such approach?

    Read the article

  • Find and replace date within a file

    - by user1629011
    My apologies if my title is not descriptive enough, I believe the following will be. I have 3 files which are just plain text, within each file, is a date Date: 2012-08-31 for example I would like to get a command/script to find this and update to the current date, but the date will be ever changing and may not be known going in (without viewing the contents of the file Knowing what the date is, its simple enough with sed, but how can I do this knowing the syntax of the line I want to modify, but not the specific values. ("Date: " at least is unchanging)

    Read the article

  • Replace Emails and HREFS with enclosing HREFS

    - by Nissan Fan
    I have an Email body that used to be plain text, but now I've made it HTML. The emails are generated using a number of methods and none of them are easy to convert. What I have is: Some content [email protected], some http://www.somewebsite/someurl.aspx. What I'd like to do is create a function that automatically encloses all email addresses and all URLs within a string in HREF tags so that the HTML email reads properly in all email clients. Does anyone have a function for this?

    Read the article

  • how to get values sent by location.replace(URL)

    - by kawtousse
    hi everyone, In my javascript function I do livke this in order to redirect parameters to servlet: var ids1=document.getElementById("projet").value; document.location.href("http://localhost:8080/Opc_Web_App/ServletAffectation?ids1="+ids1); and in the servlet I do the following to get Value: String idprojet= request.getParameter("projet"); System.out.println("le projet selectionné est :" +idprojet); the problem that i didnt have the result of System.out.print in my screen; so in other terms the servlet didn't get the parameter. I can not see the problemn untill now. Please help. Thank you.

    Read the article

  • Pattern match and replace in Javascript

    - by T_t
    There is something in my mind: In a web page,there are lots of things we can see from our browser.One of them is text. Now i have some patterns,"abc","hello",or some other strings.In the text, i want to find all the patterns and change the color or background-color of them. Like this: text: what a wonderful day! pattern: "a","day" resulet: what a wonderful day! How can solve this whit Javascript?

    Read the article

< Previous Page | 62 63 64 65 66 67 68 69 70 71 72 73  | Next Page >