UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

336 lines (253 loc) 8.59 kB
<!-- Generated by Rakefile:build --> <strong> <a href="http://an3m1.com/" rel="nofollow">????? ????????</a> </strong> on 2012-05-06 09:32:18 <br /> Great job here. I really enjoyed what you had to say. Keep going because you definitely bring a new voice to this subject. Not many people would say what you’ve said and still make it interesting <hr /> <strong> <a href="ajkds@ff.com" rel="nofollow">praveen</a> </strong> on 2012-03-30 14:31:30 <br /> oka mukka ardam kaledu ra yedava <hr /> <strong> <a href="ajkds@ff.com" rel="nofollow">praveen</a> </strong> on 2012-03-30 14:29:59 <br /> adsdajdhadehaijdeiojni bondha <hr /> <strong> ? </strong> on 2011-07-28 11:00:22 <br /> ' <hr /> <strong> <a href="http://www.divasbydesign.co.za" rel="nofollow">Denis</a> </strong> on 2011-05-05 10:31:29 <br /> I found this very helpful in my coding :) <hr /> <strong> <a href="www.divasbydesign.co.za" rel="nofollow">Denis</a> </strong> on 2011-05-05 10:30:40 <br /> very helpful :) <hr /> <strong> ball </strong> on 2010-12-25 03:05:13 <br /> thanks a lot!!! <hr /> <strong> <a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a> </strong> on 2010-04-11 08:58:25 <br /> @Oskar: Thanks, good point! Changed in git... <hr /> <strong> <a href="http://oskar-lh.name" rel="nofollow"></a> </strong> on 2010-04-11 01:00:00 <br /> Hi, replace(/[\\&quot;']/g, &quot;\\$&amp;&quot;) might be faster than replace(/([\\&quot;'])/g, &quot;\\$1&quot;) <hr /> <strong> <a href="http://oskar-lh.name" rel="nofollow"></a> </strong> on 2010-04-11 00:58:56 <br /> Hi, <pre><code>replace(/[\\&quot;']/g, &quot;\\$&amp;&quot;)</code></pre> might be faster than <pre><code>replace(/([\\&quot;'])/g, &quot;\\$1&quot;)</code></pre> <hr /> <strong> <a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a> </strong> on 2009-06-30 11:45:20 <br /> @Denny: Thanks for the report. I've fixed it in SVN. (use \u0000 instead--&quot;\u&quot; indicates a 4-digit hexadecimal Unicode sequence and \0 was a shortcut for this) <hr /> <strong> Denny Wardhana </strong> on 2009-06-30 08:40:10 <br /> Under &quot;Strict Warnings&quot; setup, <pre><code> /\0/g </code></pre> produces Warning: non-octal digit in an escape sequence that doesn't match a back-reference. How to remove that warning (and the function still working of course)? <hr /> <strong> Julien Paquit </strong> on 2008-09-23 00:14:19 <br /> Kevin : you are totally right. That was just a tip ;) <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2008-09-21 22:01:07 <br /> @ Julien Paquit: Thank you but I believe PHP does not do that automatically? If not, then we should not either, because we may surprise developers &amp;amp; cause unexpected output. <hr /> <strong> Julien Paquit </strong> on 2008-09-21 15:37:57 <br /> Very useful code ! Because of some scripting needs (and compatibility), I add this portion of code to the original one : <pre><code> return (str+'').replace(/([&amp;quot;])/g, &amp;quot;&amp;amp;quot;&amp;quot;).replace(/([\\'])/g, &amp;quot;\\$1&amp;quot;).replace(/\0/g, &amp;quot;\\0&amp;quot;); </code></pre> Now I am able to pass recursively parameters without errors. <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2008-08-27 18:10:59 <br /> @ Nate &amp;amp; Onno Marsman: Awesome job guys! I have been fooled by my tester for a long time. Addslashes has ben updated, and you have been credited accordingly. I've also changed the new testsuite to support addslashes behaviour. <hr /> <strong> Onno Marsman </strong> on 2008-08-08 11:49:10 <br /> It's probably also a good idea to convert str to a string to make sure .replace exists. addslashes(6) does work in PHP but not in this function <pre><code> return (str+'').replace(/([\\&amp;quot;'])/g, &amp;quot;\\$1&amp;quot;).replace(/\0/g, &amp;quot;\\0&amp;quot;); </code></pre> <hr /> <strong> Nate </strong> on 2008-07-22 07:41:52 <br /> I couldn't get the function to work at first. I made some changes, and here is what I came up with: <pre><code> return str.replace(/([\\&amp;quot;'])/g, &amp;quot;\\$1&amp;quot;).replace(/\0/g, &amp;quot;\\0&amp;quot;); </code></pre> Also, the example should read, &amp;quot;kevin\\\'s birthday&amp;quot; because the \' becomes '. That is why it appears to work in the tester script. <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2008-05-31 14:29:19 <br /> @ Dudi: That's just my blog messing up 'addslashes'. Fixed though. <hr /> <strong> Dudi </strong> on 2008-05-30 22:57:47 <br /> It doesn't seem like the function works. And the example is wrong again. ;-) <hr /> <strong> Sean Gallagher </strong> on 2008-05-24 01:03:58 <br /> Here is another quicky but good add slashes function! P.S. I could not get your function to work. <pre><code> function addslashes(str) { // http://www.atlwebsite.com // By Sean Gallagher // Example: addslashes('what &amp;quot;ya\'ll&amp;quot; doing?') // Returns: what \&amp;quot;ya\'ll\&amp;quot; doing? str = str.replace(/'/g,&amp;quot;\\'&amp;quot;); return str.replace(/&amp;quot;/g,'\\&amp;quot;'); } </code></pre> <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2008-04-13 12:34:05 <br /> @ Jonas Raoni: I believe your proposal has the same regex, only here it's singlequoted for compatbility with Dean Edwards packer. <hr /> <strong> Jonas Raoni </strong> on 2008-04-12 17:48:16 <br /> It's missing the &amp;quot;\&amp;quot; escape. return str.replace(/([&amp;quot;'\\])/g, &amp;quot;\\$1&amp;quot;).replace(/\0/g, &amp;quot;\\0&amp;quot;) ; Or return str.replace(/([&amp;quot;'\\\0])/g, function(_, n){ return &amp;quot;\\&amp;quot; + (n == &amp;quot;\0&amp;quot; ? &amp;quot;0&amp;quot; : n); }); <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2008-03-01 17:02:17 <br /> @ Martin: Fixed! <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2008-02-28 12:58:55 <br /> @ Martin: Thanks for noticing. If you look at the source code, you see that the example is correct. But my blog probably filters out the backslash again. I'll look into it! <hr /> <strong> Martin </strong> on 2008-02-27 23:47:40 <br /> example 1 (the only one) on this page is incorrect, in that it doesn't actually add the slash. hehe. <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2008-01-23 20:24:09 <br /> @ Ates Goral: Processed. <hr /> <strong> Ates Goral </strong> on 2008-01-23 18:18:10 <br /> Additional test case: <pre><code> // * example 2: addslashes(&amp;quot;\&amp;quot;'\\\0&amp;quot;); // * returns 2: &amp;quot;\\\&amp;quot;\\\'\\\\\\\0&amp;quot; </code></pre> <hr /> <strong> Ates Goral </strong> on 2008-01-23 18:14:03 <br /> First, just a nitpick: A set of characters can be used instead of the ORs: <pre><code> return str.replace(/([&amp;quot;'\\])/g, &amp;quot;\\$1&amp;quot;); </code></pre> To add support for NUL: <pre><code> return str.replace(/([&amp;quot;'\\])/g, &amp;quot;\\$1&amp;quot;).replace(/\0/g, &amp;quot;\\0&amp;quot;); </code></pre> <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2008-01-22 07:40:04 <br /> @ booeyOH: It sure is! Thank you! <hr /> <strong> booeyOH </strong> on 2008-01-21 18:35:41 <br /> preg_quote() function for adding slashes to RegEx Not sure if it is out there, but needed something quick, hope its helpful <pre><code> function preg_quote( str ) { var quote_chars = [&amp;quot;\\&amp;quot;, &amp;quot;.&amp;quot;, &amp;quot;+&amp;quot;, &amp;quot;*&amp;quot;, &amp;quot;?&amp;quot;, &amp;quot;[&amp;quot;, &amp;quot;^&amp;quot;, &amp;quot;]&amp;quot;, &amp;quot;$&amp;quot;, &amp;quot;(&amp;quot;, &amp;quot;)&amp;quot;, &amp;quot;{&amp;quot;, &amp;quot;}&amp;quot;, &amp;quot;=&amp;quot;, &amp;quot;!&amp;quot;, &amp;quot;&amp;lt;&amp;quot;, &amp;quot;&amp;gt;&amp;quot;, &amp;quot;|&amp;quot;, &amp;quot;:&amp;quot;]; var return_val = str; for(var i=0;i&amp;lt;quote_chars.length;i++) { eval(&amp;quot;var pattern = /\\&amp;quot;+quote_chars[i]+&amp;quot;/gi&amp;quot;); return_val = return_val.replace(pattern, chr(92)+quote_chars[i]); } return return_val; } </code></pre> <hr />