Search Results

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

Page 1/395 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Is there a way to pass another parameter in the preg_replace_callback callback function?

    - by DaNieL
    mmmh guys, i really hope my english is good enaught to explain what i need. Lets take this example (that is just an example!) of code: class Something(){ public function Lower($string){ return strtolower($string); } } class Foo{ public $something; public $reg; public $string; public function __construct($reg, $string, $something){ $this->something = $something; $this->reg = $reg; $this->string = $string; } public function Replace(){ return preg_replace_callback($this->reg, 'Foo::Bar', $this->string); } public static function Bar($matches){ /* * [...] * do something with $matches and create the $output variable * [...] */ /* * I know is really useless in this example, but i need to have an istance to an object here * (in this example, the Something object, but can be something else!) */ return $this->something->Lower($output); } } $s = new Something(); $foo = new Foo($myregexp, $mystring, $s); $content = $foo->Replace(); So, the php manual say that to use a class method as callback in preg_replace_callback(), the method must be abstract. I need to pass an instance of a previuosly initialized object (in the example, an instance of the Something class) at the callback function. I tryed to use call_user_func(), but doesnt work (becose in this way i miss the matches parameter). Is there a way to do that, or have i to separate the process (doing before preg_match_all, for each match retrieve the replace value, and then a simple preg_replace)?

    Read the article

  • jquery animation callback - how to pass parameters to callback

    - by Hans
    I´m building a jquery animation from a multidimensional array, and in the callback of each iteration i would like to use an element of the array. However somehow I always end up with last element of the array instead of all different elements. html: <div id="square" style="background-color: #33ff33; width: 100px; height: 100px; position: absolute; left: 100px;"></div> javascript: $(document).ready(function () { // Array with Label, Left pixels and Animation Lenght (ms) LoopArr = new Array( new Array(['Dog', 50, 500]), new Array(['Cat', 150, 5000]), new Array(['Cow', 200, 1500]) ); $('#square').click(function() { for (x in LoopArr) { $("#square").animate({ left: LoopArr[x][0][1] }, LoopArr[x][0][2], function() { alert (LoopArr[x][0][0]); }); } }); }); ` Current result: Cow, Cow, Cow Desired result: Dog, Cat, Cow How can I make sure the relevant array element is returned in the callback?

    Read the article

  • How do I get preg replace to work when the url contains a hashtag

    - by Steven
    I found a function online for turning a url within a string into a clickable link. However, when the url contains a hashtag it doesn't work. eg. http://www.bbc.co.uk/radio1/photos/fearnecotton/5759/1#gallery5759 Here's the part of the function concerned: $ret = preg_replace( "#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret ); $ret = preg_replace( "#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret ); Any ideas? thanks

    Read the article

  • in php how do I use preg replace to turn a url into a tinyurl

    - by Steven
    I need to convert a string of text containing a long url into the same string but with a tinyurl (using the tinyurl api). eg. convert "blah blah blah /http://example.com/news/sport blah blah blah" into "blah blah blah http://tinyurl.com/yaeocnv blah blah blah". How can it be done? PLEASE NOTE I added a slash before the long url as I'm only allowed to post one link

    Read the article

  • Search and replace global modifier

    - by mrucci
    Is there any reason why non-global/first-occurrence substitution is the default in many text editing programs (vim, sed, perl, etc.)? I am talking about the /g flag of search and replace commands like: :s/pan/focaccia/g # in vim sed 's/sfortuna/fortuna/g' # with sed that will substitute every occurrence of the search pattern with the replacement string. After (not too) many years of vim and sed usage I still did not find any use case for non-global substitutions. Is there some valid historical reason? Or it is because it is? Thanks.

    Read the article

  • Supplying a callback to Jeditable

    - by pjmorse
    Summary: When I try supplying a onsubmit or onreset callback to Jeditable, I get Object [function] has no method 'apply' errors. How I got here: I've been working on a rails plugin to supply Jeditable and jWYSIWYG for in-place WYSIWYG editing. Development is driven by a Rails project I'm working on which asks for specific functions. One of the options I added was the ability to trigger Jeditable's edit mode using a button instead of clicking on the editable text itself, following the pattern suggested in this answer. The next step, though, is to hide the button while in edit mode, and reveal it again when leaving edit mode. The hide is easy enough; I just added a line to the triggering function which sends .toggle() to the button. Reveal is trickier. I figure I need to .toggle() again on submit or cancel, and helpfully, Jeditable offers onsubmit and onreset callbacks. However, when I try using those callbacks, I get this Object [something] has no method 'apply' errors. What I'm trying: Because this is in the context of a Rails helper, the actual mechanics are a little more involved than this, but the upshot is that I'm trying to follow this pattern, handing Jeditable this in the args: "onsubmit":"showTrigger", and then including this script: function showTrigger(settings, original) { $(".edit_trigger[id='element_id']").toggle(); } However, on submitting changes or canceling an edit, I get the error Object showTrigger has no method 'apply' ...as described above. I also tried sending in a function directly as the "onsubmit" argument (i.e. "onsubmit": "function(settings, original){$(\".edit_trigger[id='element_id']\").toggle();}" and then I just get Object function(settings, original){$(\".edit_trigger[id='element_id']\").toggle();} has no method 'apply' instead. There must be something wrong with how I'm handing in this callback. Any ideas? ETA: This answer suggests to me that somehow I'm providing a string to Jeditable when it expects a function instead. However, because I'm working within the context of a Rails helper, I'm not at all sure how to fix that - the "showTrigger" bit is set as a Ruby variable in the helper, and although window.showTrigger() is defined when the window is loaded, I don't know how to designate that function within a Ruby variable such that it will be recognized as a function at page load time.

    Read the article

  • python3: removing several chars from a string with a long chain of .replace().replace().replace()

    - by MadSc13ntist
    I found this example on stack overflow. I understand it, but seems like a bit much for such a simple method concept... removing several chars from a string. import string exclude = set(string.punctuation) s = ''.join(ch for ch in s if ch not in exclude) is there a builtin string method in python 3.1 to do something to the tune of: s = "a,b,c,d,e,f,g,h,i" s = s.strip([",", "d", "h"]) instead of: s = s.replace(",", "").replace("d", "").replace("h", "")

    Read the article

  • Replace this Hex chars from string in PHP

    - by Guillermo
    I'm generating an XML from data that comes from database (and some JSON feeds). I'm having some problems with some texts that contains some hex chars that are breaking my XML. For example, see this screenshot of the error I get from Chrome: I identified the hex characters that are giving me problems (I believe they're called control characters). And these are: 0x03 0x05 0x16 0x0E How can I replace those characters with PHP before printing them on my XML output? Thanks!

    Read the article

  • PHP Find and replace after in a string?

    - by TheBlackBenzKid
    I have some strings which contain the words LIMIT 3, 199 or LIMIT 0, 100. Basically I want to replace the word LIMIT and everything after it in my string. How do I do this in PHP? str_replace only replaces an item and the LIMIT text after is dynamic/ So it could be WHEN JOHN WAS TRYING HIS SQL QUERY, HE FOUND THAT LIMIT, 121 // RETURN WOULD BE WHEN JOHN WAS TRYING HIS SQL QUERY, HE FOUND THAT WHEN JOHN TRIED LIMIT 343, 333 HE FOUND // RETURN WOULD BE WHEN JOHN TRIED

    Read the article

  • js - using replace method to replace html element

    - by Rueta
    hi everyone! i have a question. I have a work this morning but i don't know how to do it. My work here (html): <div class="demo"> <p>this is demo text</p> </div> here is my JS : var tempdata = $(".demo").text(); var replacedata = tempdata.replace("text","<span>1234</span>"); Look everything ok. but result is : this is demo <span>1234</span>. this isn't my result i want. How to make in this string become a HTMLelement by using replace method?

    Read the article

  • Replace text with other text in the same line

    - by skerit
    I don't know if I can use regex for this, but I want to replace something in this xml: <custom-attribute name="Attribute_1" dt:dt="string">Danny Boyle</custom-attribute> <custom-attribute name="DVD-releasedatum" dt:dt="string">06/10/1999</custom-attribute> should become <Attribute_1>Danny Boyle</Attribute_1> <DVD-releasedatum>06/10/1999</DVD-releasedatum> Removing this from the first tag isn't hard, but how can I close my newly formed tag?

    Read the article

  • replace all link href's with return of a function, with regex

    - by Rajat Singhal
    I have a function which returns a modified url, if passed a url.. I need to call this function on hrefs of all the links in my html data.. I can't use DomDocument, it's in php cli, I need regex solution.. I have tried preg_replace, and preg_replace_callback, but I simply don't understand the whole concept of using $1, $2 in the replacement string..If somebody can point to a good documentation,that'll be great too.. function modifyUrl($old_url) { ...... return $new_url; } $html = "...";//Long html content having links //need to call modifyUrl for all link's hrefs..

    Read the article

  • Receiving an object in a unmanaged callback function

    - by Daniel Baulig
    Eg. I have following delegate method I want to use as a callback function with unmanaged code: public delegate void Callback(IntPtr myObject); Callback callback; I register it in the following way: [DllImport("a.dll")] public static void registerCallback(IntPtr callbackFunction, IntPtr anObject); // ... this.myObject = new MyClass(); this.objectPin = GCHandle.Alloc(this.myObject, GCHandleType.Pinned); registerCallback(Marshal.GetFunctionPointerForDelegate(callback), objectPin.AddrOfPinnedObject()); Now whenever the callback function is called it will have a Pointer/Handle of an object of the MyClass class. I could use Marshal.PtrToStructure to convert this to an object of MyClass. However, what I would like to have is that the delegate definition already contains the class MyClass. eg.: public delegate void Callback(MyClass myObject); I tried this, but it will not work. I also tried the following, which did not work: public delegate void Callback([MarshalAs(UnmanagedType.IUnknown)]MyClass myObject); I suppose I would need something like "UnmarshalAs" at this point, but sadly this is not available. Any suggestions how I could get lost of that IntPtr in my callback function and get a it packed up as a regular, managed MyClass object?

    Read the article

  • jquery find and replace multiple items

    - by client
    I have a monthly table that needs to be translated for each languages Something like this (doesnt work obviously) $('.lang-en #monthly th').each(function() { var text = $(this).text(); $(this).text(text.replace('Tam', 'Jan')); $(this).text(text.replace('Hel', 'Feb')); $(this).text(text.replace('Maa', 'Mar')); $(this).text(text.replace('Huh', 'Apr')); $(this).text(text.replace('Tou', 'May')); $(this).text(text.replace('Kes', 'Jun')); $(this).text(text.replace('Hei', 'Jul')); $(this).text(text.replace('Elo', 'Aug')); $(this).text(text.replace('Syy', 'Sep')); $(this).text(text.replace('Lok', 'Oct')); $(this).text(text.replace('Mar', 'Nov')); $(this).text(text.replace('Jou', 'Dec')); $(this).text(text.replace('Yht', 'Total')); });

    Read the article

  • PHP Replace chars by functions

    - by user1860570
    I try change characters by functions <?php $string = "Hi everybody people [gal~images/articles~100~100~4] here other imagen [gal~images/products~100~100~3]"; $regex = "/\[(.*?)\]/"; preg_match_all($regex, $string, $matches); for($i=0; $i<count($matches[1]);$i++) { $match = $matches[1][$i]; $array = explode('~', $match); //$newValuet="gal("".$array[1]."","".$array[2]."","".$array[3]."","".$array[4]."")"; $newValue="gal(".$array[1].",".$array[2].",".$array[3].",".$array[4].")"; $string = str_replace($matches[0][$i],$newValue,$string); } echo $string; ?> The problem here : $newValue="gal(".$array[1].",".$array[2].",".$array[3].",".$array[4].")"; $string = str_replace($matches[0][$i],$newValue,$string); Function no give the right results i try differents methods but continue the problems , please i see all functions but no get this works if you can answer please put me some modification of this code for i can understand , thank´s a lot for all help

    Read the article

  • Twitter's Bootstrap 2.x popover callback can't focus on element

    - by mozgras
    I've modified bootstrap's popover function to include a callback which works great. But in the callback I cannot programmatically focus on the first form field. Strange, because I can manipulate other elements in the callback function as well as focus on the element at other points. Here's the code to add a callback which I got from another SO question (http://stackoverflow.com/a/14727204/1596547): var tmp = $.fn.popover.Constructor.prototype.show; $.fn.popover.Constructor.prototype.show = function () { tmp.call(this); if (this.options.callback) { this.options.callback(); } } Here's the popover code: $('#a-editor-btn').popover({ html: true, placement: 'bottom', callback: function(){ $('#a-form-point').focus(); //nothing happens console.log('hello'); // works . . }, content: $('#a-form').html() }).parent().delegate('button#insert-point-btn', 'click', function() { insertPoint(); }).delegate('.a-form','keypress', function(e) { if ( e.which == 13 ) { insertPoint(); } });

    Read the article

  • php preg replace

    - by David
    I'm trying to build a PHP preg replace string when processing poorly written xml, such that if I am given: $x='<abc x="y"><def x="g">more test</def x="g"><blah>test data</blah></abc x="y">'; That it checks if there's a space within a closing tag and deletes everything from the space to the end of the tag such that. becomes <abc x="y"><def x="g">more test</def><blah>test data</blah></abc> thanks

    Read the article

  • Find and Replace several several different values all at once

    - by matt
    I have a file with multiple instances of Text_1 and Text1 and I need to replace both those strings with Text_A and TextB respectively. Currently I'm doing two Find and Replace functions on each file one that finds Text_1 and replaces it with Text_A and the other that finds Text1 and replaces it with TextB. Is there any way to do this all at once instead of having to run "Find and Replace" twice? I am using Dreamweaver CS3, but I also have Notepad++, regular Notepad, OO Writer, MS Word if those will be easier. Ideally I could do this in Dreamweaver or Notepad++ but I'm open to downloading something else to get the job done. I'd prefer not to have to do any command line stuff or create a batch file (while I'm aware of it, I don't understand it really). Edit: In case the above description isn't clear, let me explain it this way... I want to run Find & Replace 1 time in 1 document and I want it to do ALL of the following during that one Find & Replace instance: Find: Text_1 and Replace with: Text_A Find: Text1 and Replace with: TextB I am not trying to do a Find and Replace across several documents.

    Read the article

  • Python objects as userdata in ctypes callback functions

    - by flight
    The C function myfunc operates on a larger chunk of data. The results are returned in chunks to a callback function: int myfunc(const char *data, int (*callback)(char *result, void *userdata), void *userdata); Using ctypes, it's no big deal to call myfunc from Python code, and to have the results being returned to a Python callback function. This callback work fine. myfunc = mylib.myfunc myfunc.restype = c_int myfuncFUNCTYPE = CFUNCTYPE(STRING, c_void_p) myfunc.argtypes = [POINTER(c_char), callbackFUNCTYPE, c_void_p] def mycb(result, userdata): print result return True input="A large chunk of data." myfunc(input, myfuncFUNCTYPE(mycb), 0) But, is there any way to give a Python object (say a list) as userdata to the callback function? In order to store away the result chunks, I'd like to do e.g.: def mycb(result, userdata): userdata.append(result) userdata=[] But I have no idea how to cast the Python list to a c_void_p, so that it can be used in the call to myfunc. My current workaround is to implement a linked list as a ctypes structure, which is quite cumbersome.

    Read the article

  • pb with callback in the python optparse module

    - by PierrOz
    Hi Guys, I'm playing with Python 2.6 and its optparse module. I would like to convert one of my arguments to a datetime through a callback but it fails. Here is the code: def parsedate(option, opt_str, value, parser): option.date = datetime.strptime(value, "%Y/%m/%d") def parse_options(args): parser = OptionParser(usage="%prog -l LOGFOLDER [-e]", version="%prog 1.0") parser.add_option("-d", "--date", action="callback", callback="parsedate", dest="date") global options (options, args) = parser.parse_args(args) print option.date.strftime() if __name__ == "__main__": parse_options(sys.argv[1:]) I get an error File: optparse.py in _check_callback "callback not callable". I guess I'm doing something wrong in the way I define my callback but what ? and why ? Can anyone help ?

    Read the article

  • A maximum character limit on the preg functions?

    - by animuson
    On my site I use output buffering to grab all the output and then run it through a process function before sending it out to the browser (I don't replace anything, just break it into more manageable pieces). In this particular case, there is a massive amount of output because it is listing out a label for every country in the database (around 240 countries). The problem is that in full, my preg_match functions seems to get skipped over, it does absolutely nothing and returns no matches. However, if I remove parts of the labels (no particular part, just random pieces to reduce characters) then the preg_match functions works again. It doesn't seem to matter what I remove from the label, it just seems to be that as long as I remove so many characters. Is there some sort of cap on what the preg functions can handle or will it time out if there is too much data to be scanned over?

    Read the article

  • PHP: Rawurlencode inside Preg-replace

    - by elmaso
    Hello, I have this snippet while($row = mysql_fetch_array($result)){ $search = '' . $row['searchquery']; echo '<a href="http://www.example.com/' . preg_replace( array('/[^\s\w]/','/\s/'),array('','+'),$search) . '+/">' ... but if someone types in äöü, it doesnt show the letters - with rawurlencode thats possible, but I want to remove the blank spaces with pregreplace and replace it with + is that possible?

    Read the article

  • jquery callback function

    - by kusanagi
    i use recaptcha Recaptcha.create("xxx", "recaptcha", { theme: 'clean', tabindex: 0, callback: $("#id").focus }); i want to use callback to focus some field, but it doesn't work, only callback: f works function f() { $("#FIO").focus(); } what is the problem?

    Read the article

  • javascript callback after loop

    - by RobertPitt
    Hey guys, Iv'e just started a new Wordpress blog and i have started to build the JavaScript base! the issue im having is funnction a fucntion that loops several variables and includes the required JS libraries, what i need to do is execute the callback when the loop is finished! Heres my code! var Utilities = { Log : function(item) { if(console && typeof console.log == 'function') { //Chrome console.log(item); } }, LoadLibraries : function(callback) { $.each(Wordpress.required,function(i,val){ //Load the JS $.getScript(Wordpress.theme_root + '/js/plugins/' + val + '/' + val + '.js',function(){ // %/js/plugins/%/%.js Utilities.Log('library Loaded: ' + val); }); }); callback(); } } And the usage is like so! Utilities.LoadLibraries(function(){ Utilities.Log('All loaded'); }); Above you see the execution of callback() witch is being executed before the files are in the dom! i need this called at the end of every library inclusion!

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >