Search Results

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

Page 41/395 | < Previous Page | 37 38 39 40 41 42 43 44 45 46 47 48  | Next Page >

  • Replace newline from MySQL TEXT field to parse w/ JSON

    - by dr3w
    Hi, "replace newline" seems to be a question asked here and there like hundred times already. But however, i haven't found any working solution for myself yet. I have a textarea that i use to save data into DB. Then using AJAX I want to get data from the DB in the backend that is in TEXT field and to pass it to frontend using JSON. But pasing JSON returns an error, as new lines from DB are not valid JSON syntax, I guess i should use \n instead... But how do i replace newlinew from DB with \n? I've tried this $t = str_replace('<br />', '\n', nl2br($t)); and this $t = preg_replace("/\r\n|\n\r|\r|\n/", "\n", $t); and using CHAR(13) and CHAR(10), and still I get an error the new line in textarea is equivalent to, i guess $t = 'text with a newline'; it gives the same error. And in notepad i clearly see that it is crlf

    Read the article

  • Chaining functions in jQuery. I cannot find an explanation anywhere.

    - by Marius
    Hello there, I have no idea how to do this. My markup: <table> <tr> <td id="colLeft"> Lorem ipsum dolor<br/> Lorem ipsum dolor<br/> Lorem ipsum dolor<br/> Lorem ipsum dolor<br/> Lorem ipsum dolor<br/> Lorem ipsum dolor. </td> <td id="colRight"> <div>1</div> <div>2</div> </td> </tr> </table> $(document).ready(function() { $('#colRight > div').each(function() { // I try to: select all divs in #colRight $(this).height(function(){ // I try to: sets the height of each div to: $('#colLeft').height() / $('#colRight > div').length(); // the height of #colLeft divided by the number of divs in colRight. }); }); }); What I am trying to do is to change the height of each div to the height of #colLeft divided by the number of divs in #colRight. However, it doesnt work. I've never understood how to chain functions, and never found anyone to teach me. So I would like to ask two favours of you. Why doesnt my above jQuery code. Does anyone know of a tutorial that explains it more detailed than in the tutorials on the jQuery website? Thank you for your time. Kind regards, Marius

    Read the article

  • Extracting Text from between parentheses in PHP using preg_replace

    - by Christopher
    I am trying to take a string of text like so: $string = "This (1) is (2) my (3) example (4) text"; In every instance where there is a positive integer inside of parentheses, I'd like to replace that with simply the integer itself. The code I'm using now is: $result = preg_replace("((\d+))", "$0", $string); But I keep getting a "Delimiter must not be alphanumeric or backslash" error. Any thoughts? I know there are other questions on here that sort of answer the question, but my knowledge of regex is not enough to switch it over to this example.

    Read the article

  • Memory leak with preg_replace

    - by Silvio Donnini
    I'm using the preg_replace function to replace accents in a string, I'm working with UTF-8. I have incurred in what seems to be a memory leak, but I can't isolate the root cause, my code is rather simple: preg_replace( array_keys($aToNoAccents), array_values($aToNoAccents), $sText ); where $aToNoAccents is an associative array with entries like '~[A]~u' => 'A', '~[C]~u' => 'C',. My script prints this error for the above line: Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 3039 bytes) Obviously it's not a matter of increasing the allowed memory for PHP, (a 1Gb footprint is way off the scale of my application). Also, that line is executed thousands of times without problems but, just for some cases which are difficult to reproduce, it yields the error. Is anyone aware of memory problems with preg_replace and UTF-8 strings? Am I to use special care in passing actual parameters to such function? I'm using PHP 5.2.6-3 with Suhosin-Patch thanks Silvio

    Read the article

  • Pass Result of ASIHTTPRequest "requestFinished" Back to Originating Method

    - by Intelekshual
    I have a method (getAllTeams:) that initiates an HTTP request using the ASIHTTPRequest library. NSURL *httpURL = [[[NSURL alloc] initWithString:@"/api/teams" relativeToURL:webServiceURL] autorelease]; ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:httpURL] autorelease]; [request setDelegate:self]; [request startAsynchronous]; What I'd like to be able to do is call [WebService getAllTeams] and have it return the results in an NSArray. At the moment, getAllTeams doesn't return anything because the HTTP response is evaluated in the requestFinished: method. Ideally I'd want to be able to call [WebService getAllTeams], wait for the response, and dump it into an NSArray. I don't want to create properties because this is disposable class (meaning it doesn't store any values, just retrieves values), and multiple methods are going to be using the same requestFinished (all of them returning an array). I've read up a bit on delegates, and NSNotifications, but I'm not sure if either of them are the best approach. I found this snippet about implementing callbacks by passing a selector as a parameter, but it didn't pan out (since requestFinished fires independently). Any suggestions? I'd appreciate even just to be pointed in the right direction. NSArray *teams = [[WebService alloc] getAllTeams]; (currently doesn't work, because getAllTeams doesn't return anything, but requestFinished does. I want to get the result of requestFinished and pass it back to getAllTeams:)

    Read the article

  • Call a constructor from variable arguments with PHP

    - by zneak
    Hello guys, I have a function that takes variadic arguments, that I obtain from func_get_args(). This function needs to call a constructor with those arguments. However, I don't know how to do it. With call_user_func, you can call functions with an array of arguments, but how would you call a constructor from it? I can't just pass the array of arguments to it; it must believe I've called it "normally". Thank you!

    Read the article

  • CFGRID - replace data store or filter on more than one column

    - by Casuzen
    ColdFusion 8 I have a cfgrid that that is based on a query. It is not bound to a cfc function because I want a scrolling grid, not a paged grid (you must supply the page number and page size if you use BIND).. I can figure out how to make it filter on one column by using the following code, but I really need to filter on three columns... grid.getDataSource().filter("OT_MILESTONE",t1); Adding more to the filter string does not do the trick...it ignores anything more than the first pair of values.. so..I thought if I called a function that passes the three values and returned the query results to me, I could replace the Data Store for the grid..but I cannot figure out the syntax to get it to replace. The returned variable for the query has the following format: {"COLUMNS":["SEQ_KEY","ID","OT_MILESTONE"],"DATA":[[63677,"x","y"]]} Any ideas?

    Read the article

  • " addressof " VB6 to VB.NET

    - by johan
    Hello, I´m having some problem to convert my VB6 project to VB.NET I dont understan how this "addressof" function should be in VB.NET My VB6 code: Declare Function MP4_ClientStart Lib "hikclient.dll" (pClientinfo As CLIENT_VIDEOINFO, ByVal abab As Long) As Long Public Sub ReadDataCallBack(ByVal nPort As Long, pPacketBuffer As Byte, ByVal nPacketSize As Long) If Not bSaved_DVS Then bSaved_DVS = True HW_OpenStream hChannelHandle, pPacketBuffer, nPacketSize End If HW_InputData hChannelHandle, pPacketBuffer, nPacketSize End Sub nn1 = MP4_ClientStart(clientinfo, AddressOf ReadDataCallBack)

    Read the article

  • Why doesn't SetNotifyWindowMessage() call my WndProc()?

    - by manuel
    I'm using WinForms, and I'm trying to get SetNotifyWindowMessage() to call the WndProc, but it does not do so. The function call: HRESULT initSAPI(HWND hWnd) { ... if(FAILED( g_cpRecoCtxt->SetNotifyWindowMessage( hWnd, WM_RECOEVENT, 0, 0 ))) MessageBoxW(hWnd, L"Error sending window message", L"SAPI Initialization Error", 0); ... } The WndProc: LRESULT WndProc (HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam) { case WM_RECOEVENT: ProcessRecoEvent(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } Note: initSAPI() is called on a mouse click event.

    Read the article

  • Javascript substrings multiline replace by RegExp

    - by Radek Šimko
    Hi, I'm having some troubles with matching a regular expression in multi-line string. <script> var str="Welcome to Google!\n"; str = str + "We are proud to announce that Microsoft has \n"; str = str + "one of the worst Web Developers sites in the world."; document.write(str.replace(/.*(microsoft).*/gmi, "$1")); </script> http://jsbin.com/osoli3/3/edit As you may see on the link above, the output of the code looks like this: Welcome to Google! Microsoft one of the worst Web Developers sites in the world. Which means, that the replace() method goes line by line and if there's no match in that line, it returns just the whole line... Even if it has the "m" (multiline) modifier...

    Read the article

  • PHP, what is the better choice for removing a known string?

    - by Brook Julias
    I am looking to search for and replace a known string from within another string. Should I use str_replace() or ereg_replace()? The string to be replaced would be something similar to [+qStr+], [+bqID+], or [+aID+] and it would be being searched for in a code chunk similar to this: <li> [+qStr+] <ol class="mcAlpha"> <li><input type="radio" name="[+bqID+]" id="[+bqID+]_[+aID+]" value="[+aID+]" /><label for="[+bqID+]_[+aID+]">[+aStr+]</label></li> </ol> </li> I would be replacing the strings with the results from a MySQL query, and be performing this action or similar up to 200 times at a time. Which function str_replace() or ereg_replace() would be the easiest and/or quickest method to take.

    Read the article

  • MS SQL replace sequence of same characters inside Text Field (TSQL only)

    - by zmische
    I have a text column varchar(4000) with text: 'aaabbaaacbaaaccc' and I need to remove all duplicated chars - so only one from sequence left: 'abacbac' It should not be a function, Procedure or CLR - Regex solution. Only true SQL select. Currently I think about using recursive WITH clause with replace 'aa'-'a', 'bb'-'b', 'cc'-'c'. So recursion should cycle until all duplicated sequences of that chars would be replaced. DO you have another solution, perhaps more Permormant one? PS: I searched through this site about different replace examples - they didnt suit to this case.

    Read the article

  • Search for a String and replace it with a variable

    - by chrissygormley
    Hello, I am trying to use regular expression to search a document fo a UUID number and replace the end of it with a new number. The code I have so far is: read_file = open('test.txt', 'r+') write_file = open('test.txt', 'w') r = re.compile(r'(self.uid\s*=\s*5EFF837F-EFC2-4c32-A3D4\s*)(\S+)') for l in read_file: m1 = r.match(l) if m1: new=(str,m1.group(2)) new?????? This where I get stuck. The file test.txt has the below UUID stored in it: self.uid = '5EFF837F-EFC2-4c32-A3D4-D15C7F9E1F22' I want to replace the part D15C7F9E1F22. I have also tried this: r = re.compile(r'(self.uid\s*=\s*)(\S+)') for l in fp: m1 = r.match(l) new=map(int,m1.group(2).split("-") new[4]='RHUI5345JO' But I cannot seem to match the string. Thanks in advance for any help.

    Read the article

  • Problem with mysql query to replace a string

    - by alex
    I've used mysql's update replace function before, but even though I think I'm following the same syntax, I can't get this to work. Here's what I'm trying to do: UPDATE contained_widgets SET preference_values = REPLACE(preference_values, '<li><a_href="/enewsletter"><span class="not-tc">eNewsletter</span></a></li>', '<li><a_href="/enewsletter"><span class="not-tc">eNewsletter</span></a></li> <li> <a_href="/projects"><span class="not-tc">Projects</span></a></li>'); Query OK, 0 rows affected (0.00 sec) Rows matched: 77 Changed: 0 Warnings: 0 I don't see what I'm missing. Any help is appreciated. I edited "a " to "a_" because the site thinks I'm posting spam links otherwise.

    Read the article

  • Same code... but warning!Any ideas?

    - by FILIaS
    I've a question for a warning message that i get. For this line,using qsort: qsort(catalog, MAX ,sizeof catalog, struct_cmp_by_amount); I get this warning: warning: passing argument 4 of ‘qsort’ makes pointer from integer without a cast struct_cmp_by_amount is another function on the program. BUT,for another program with the same code, with the same exactly struct_cmp_by_amount function, i dont get that warning for the 4th argument! qsort(structs, structs_len, sizeof(struct st_ex), struct_cmp_by_price); I'm wandering about why that;s happening. Have you any idea?

    Read the article

  • jQuery - want to get input value for submit but it gets one and repeats

    - by jquery n00b
    I'm trying to replace all submit buttons with a span so cufon will work. The input still needs to be there so have done some css to hide it and overlay to span on top. My issue is getting the value from the input tag is proving quite diffcult. The code below gets the first input value (being 'search' from the search box at the top of the page, and then puts that value into all the spans, even for buttons that have different values (eg: send). This is a .NET page so the whole page is wrapped in one form tag. Any help is greatly appreciated. jQUERY: jQuery(document).ready( function() { jQuery(".button-wrap input.button").each(function() { var values = jQuery(".button-wrap input").attr('value'); jQuery(this).before("<span class='input-replacer'>" +values+ "</span>"); });

    Read the article

  • Replace repeating character with array elements in PHP

    - by Will Croft
    I hope this is blindingly obvious: I'm looking for the fastest way to replace a repeating element in a string with the elements in a given array, e.g. for SQL queries and parameter replacement. $query = "SELECT * FROM a WHERE b = ? AND c = ?"; $params = array('bee', 'see'); Here I would like to replace the instances of ? with the corresponding ordered array elements, as so: SELECT * FROM a WHERE b = 'bee' and c = 'see' I see that this might be done using preg_replace_callback, but is this the fastest way or am I missing something obvious?

    Read the article

  • can this code be broken?

    - by user105165
    Consider the below html string <p>This is a paragraph tag</p> <font>This is a font tag</font> <div>This is a div tag</div> <span>This is a span tag</span> This string is processed to tokanize the text found in it and we get 2 results as below 1) Token Array : $tokenArray == array( 'This is a paragraph tag', 'This is a div tag', '<font>This is a font tag</font>', '<span>This is a span tag</span>' ); 2) Tokenized template : $templateString == "<p>{0}</p>{2}<div>{1}</div>{3}"; If you observe, the sequence of the text strings segments from the original HTML strings is different from the tokenized template The PHP code below is used to order the tokenized template and accordingly the token array to match the original html string class CreateTemplates { public static $tokenArray = array(); public static $tokenArrayNew = array(); function foo($templateString,$tokenArray) { CreateTemplates::$tokenArray = $tokenArray; $ptn = "/{[0-9]*}*/"; // Search Pattern from the template string $templateString = preg_replace_callback($ptn,array(&$this, 'callbackhandler') ,$templateString); // function call return $templateString; } // Function defination private static function callbackhandler($matches) { static $newArr = array(); static $cnt; $tokenArray = CreateTemplates::$tokenArray; array_push($newArr, $matches[0]); CreateTemplates::$tokenArrayNew[count($newArr)] = $tokenArray[substr($matches[0],1,(strlen($matches[0])-2))]; $cnt = count($newArr)-1; return '{'.$cnt.'}'; } // function ends } // class ends Final output is (ordered template and token array) $tokenArray == array('This is a paragraph tag', '<font>This is a font tag</font>', 'This is a div tag', '<span>This is a span tag</span>' ); $templateString == "<p>{0}</p>{1}<div>{2}</div>{3}"; Which is the expected result. Now, I am not confident whether this is the right way to achieve this. I want to see how this code can be broken or not. Under what conditions will this code break? (important) Is there any other way to achieve this? (less important)

    Read the article

  • Replace xml tag with regex

    - by Kai
    How can I replace a certain part in a xml file with a definied string? <tag1></tag2> <tag2></tag2> ...etc <soundcard num=0> <name>test123</name> </soundcard> <soundcard num=1> <name>test123</name> </soundcard> <soundcard num=2> <name>test123</name> </soundcard> <tag5></tag5> replace all soundcard parts that the result looks like that: <tag1></tag2> <tag2></tag2> ...etc {0} <tag5></tag5> I'm using c# .net 3.5 and I thougt of a regex solution

    Read the article

  • Batch file search and replace using wildcards?

    - by user329358
    Batch file search and replace using wildcards I have a html (txt) file I am using as a template or sourcefile to create further html files.  Filename = pg_0001.htm and it contains a line of code thus: pg_0001.jpg I want to parse the pg_0001.htm sourcefile, increment and replace the jpeg string, like this:  "pg_0002.jpg", and then output the edited htm file to a new filename pg_0002.htm I then take each newly created file (pg_0002.htm, pg_0003.htm etc) as the sourcefile and repeat the processing until I have reached my target goal (let's say 100 newly created htm files containing code to display the corresponding jpeg. It must be done this way (fileX.htm containing fileX.jpg) because there is other javascript that uses these incremented filenames as function input. I used to know how to write incrementing batch files many years ago but I'm old & very rusty now.  Can anyone please help me do this?  Many thanks in advance. regards Harry

    Read the article

  • Create thread is not accepting the member functon

    - by prabhakaran
    I am trying to create a class for network programming. This will create a general purpose socket with thread. But when I tried to creat the thread using createthread(). The third argument is producing errors. And from the net I came to know that I can't use the member functions as a argument to the createthread(). Is there any thing by which I can achieve this.

    Read the article

  • Highlite words from searchstring

    - by Bundy
    Hi, I wrote a little search script for a client, it works and words get highlited, BUT... Imagine this situation: search term: test found result: Hello this <a href="/news/this-is-a-test">is a test</a> In this example both 'test' in the href part and between the <a> tags get highlited, breaking the link. How could I prevent this? Edit: So this is what I need: A regex replace function that replaces all matched search strings EXCEPT the ones that are located inside a href attribute Greets, nick

    Read the article

  • How can I replace a line which contains only -------- by |||

    - by mimou
    I have something like: ------------------------------------------------------------------------ r2 | username | 2011-01-16 16:52:23 +0100 (Sun, 16 Jan 2011) | 1 line Changed paths: D /foo Removed foo ------------------------------------------------------------------------ r1 | username | 2011-01-16 16:51:03 +0100 (Sun, 16 Jan 2011) | 1 line Changed paths: A /foo created foo ------------------------------------------------------------------------ My target is to identify the file added by the "username" in a specific date. Thus, I need to have the combination (username, 16 Jan 2011, A) to insure that it is the right file ands then print foo. My idea is to: delete the white spaces change the newlines into | get rid of the --------------- and replace them with newlines but the problem is that I couldn't replace the ------- since they are mixed with other characters. ------------------------------------------------------------------------ |r2|username|2011-01-1616:52:23+0100(Sun,16Jan2011)|1line|Changedpaths:|D/foo|Removedfoo| ------------------------------------------------------------------------ |r1|username|2011-01-1616:51:03+0100(Sun,16Jan2011)|1line|Changedpaths:|A/foo|createdfoo| ------------------------------------------------------------------------ So I thought it would be a good idea to start by replacing the --------------- by a special character like ||| and then change this character by a newline using awk FS=||| OFS=\n Can anyone help me! thanks

    Read the article

< Previous Page | 37 38 39 40 41 42 43 44 45 46 47 48  | Next Page >