/_octopress/source/functions/strtr/_comments.html
HTML | 316 lines | 248 code | 67 blank | 1 comment | 0 complexity | ee12407c0acbd67477fec1e96a8a8c1a MD5 | raw file
- <!-- Generated by Rakefile:build -->
- <strong>
- <a href="http://an3m1.com/" rel="nofollow">????? ????????</a>
- </strong>
- on 2012-04-10 09:52:43 <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>
- Theriault
- </strong>
- on 2011-05-13 10:28:09 <br />
- @Breton: I can't verify it because I don't have IE9, but my guess on a fix would be changing line 55 from...
- <pre><code>
- tmpFrom.push(fr);
- </code></pre>
- to...
- <pre><code>
- tmpFrom.push('' + fr);
- </code></pre>
- Let us know if this fixes it.
- <hr />
- <strong>
- Breton
- </strong>
- on 2011-05-10 11:24:02 <br />
- Hi, there is a new bug in IE9 with the function strtr !
- This line doesn't work : "if (str.substr(i, from[j].length) == from[j]) {"
- Have you got any idea ?
- You can see the error here : http://imageshack.us/photo/my-images/805/bugc.jpg/
- Fucking IE ! ^^'
- <hr />
- <strong>
- <a href="http://preseka.mygamesonline.com" rel="nofollow">odin</a>
- </strong>
- on 2011-03-27 23:45:26 <br />
- Hey i maid even bether one look down:
- it contanis 0 loops for norma use and 1 loop for advanced use
- <pre><code>
- function strtr(s,f,t)
- {
- core=function(str,from,to){//core function
- str=str.split(from);//breake parts that we wan't to
- str=str.join(to);//glue with new parts that we wan't to
- return str;
- };//end of core function
- if(!t){//check if we use advanced option
- r=s;
- for(e in f){//loop
- r=core(r,e,f[e]);//call our core function
- }
- return r;// end code and retun value
- }
- //normal use
- return core(s,f,t); // just call normal core function and return
- }
- /*
- example:
- normal use:
- strtr("This string is string.","string","text");
- =This text is text.
- advanced use
- strtr("This string is texty.",{'texty':'text','string':'text'});
- =This text is string.
- advanced use WARNING!
- strtr("This string is text.",{'text':'string','string':'text'});
- =This text is text.
- this is not switcher it's replacer!!
- */
- </code></pre>
- <hr />
- <strong>
- <a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a>
- </strong>
- on 2010-12-02 09:55:47 <br />
- @Robert: Please try your function against the existing examples to make sure it works. Thanks...
- <hr />
- <strong>
- Robert
- </strong>
- on 2010-12-01 20:41:28 <br />
- What about something more like this? I saw an example of using this for urlencode and thought it would work well for strtr.
- <pre><code>
- function strtr(base, old, n){
- return base.replace(/[A-Za-z0-9_.-]/g, function (s) {
- for (var k = 0; k < old.length; k++) {
- if (s == old.charAt(k) && k < n.length) {
- return n.charAt(k);
- }
- }
- });
- }
- </code></pre>
- <hr />
- <strong>
- jpfle
- </strong>
- on 2009-12-11 16:20:54 <br />
- @Brett: it works very great now. Thanks again! :-)
- <hr />
- <strong>
- <a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a>
- </strong>
- on 2009-12-11 12:40:42 <br />
- @jpfle: Sorry, I had also needed to update krsort() recently too. Please use the version at http://github.com/kvz/phpjs/blob/master/functions/array/krsort.js
- <hr />
- <strong>
- jpfle
- </strong>
- on 2009-12-11 04:25:40 <br />
- @Brett: Thanks for your answer. However, it no longer works neither on Firefox nor IE. Here's what I packaged on phpjs.org:
- - `i18n_loc_get_default()`
- - `i18n_loc_set_default()`
- - `ini_set()`
- - `krsort()`
- - `strtr()`
- and then I replaced `strtr()` by github's version. With the same code of my previous comment, "ça et là" is output on Firefox and IE without any translation, namely "ça et là". Firefox's Error Console is empty.
- <hr />
- <strong>
- <a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a>
- </strong>
- on 2009-12-10 05:42:56 <br />
- @jpfle: Should now be fixed: http://github.com/kvz/phpjs/blob/master/functions/strings/strtr.js . Please note that I've needed to add a new dependency: ini_set(). Also, this will not work with IE5 as is, since I also added for-in filtering for hasOwnProperty (you can remove the check (or alter it to at least make sure from[fr] is a string) if you need to support IE5, but you risk interfering with other libraries that override the Object prototype; otherwise it's best to leave it as is).
- <hr />
- <strong>
- jpfle
- </strong>
- on 2009-12-09 22:30:16 <br />
- Hi. Thanks for this useful function. I use it in a script generating a table of contents for XHTML pages. Each title in a page is transliterated ('à' => 'a', 'é' => 'e', 'î' => 'i', etc.) with strstr() to create an anchor. However, there's a bug with Internet Explorer 6. Take this code:
- <pre><code>
- var texte = 'çà et là';
- texte = strtr(texte, {'ç': 'c', 'à': 'a', ' ': '-'});
- alert(texte);
- </code></pre>
- Firefox (3.5.5) outputs "ca-et-la", as expected, but IE6 outputs "ca-undefinedundefined-undefineda".
- <hr />
- <strong>
- kwemart
- </strong>
- on 2009-11-20 12:10:58 <br />
- @kevin van
- yes I know my function is just for regulars expressions
- it wouldn't work with ayyay but I'll update it later
- cheer .
- <hr />
- <strong>
- <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
- </strong>
- on 2009-11-07 18:50:03 <br />
- @ kwemart: Thanks for sharing. However with your code, only the 3rd example produces the expected output. The other ones fail :(
- <hr />
- <strong>
- kwemart
- </strong>
- on 2009-10-31 12:25:41 <br />
- hi this function is very nice but I propose an other solution , it only work with a regular expression.
- <pre><code>
- function strtr(str,from,to)
- {
- var patt=str.split(from),str2="";
- var l=patt.length,i=1;
- while(i<=l-1){str=str.replace(from,to);i+=1;}
- return str;
- }
- </code></pre>
- <hr />
- <strong>
- <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
- </strong>
- on 2009-07-03 13:52:01 <br />
- @ Roland Hentschel: Thanks for sharing
- @ Frank Forte & T.Wild: Cool, let's continue at the page suggested by T.Wild
- <hr />
- <strong>
- T.Wild
- </strong>
- on 2009-07-02 22:59:55 <br />
- @Frank Forte
- You may want to post your problem over at
- http://phpjs.org/functions/htmlspecialchars
- rather than here on strtr
- <hr />
- <strong>
- <a href="http://thenetgen.com/" rel="nofollow">Frank Forte</a>
- </strong>
- on 2009-07-02 15:25:46 <br />
- I found the following error with the htmlspecialchars() function when doing the following:
- <pre><code>
- el.innerHTML = htmlspecialchars('test 1 < 2 ');
- </code></pre>
- The output (inserted into the element) was
- 'test 1 &lt; 2'
- The htmlspecialchars function does this:
- step 1 < turns to &lt;
- step 2 &lt; turns to &amp;lt;
- This is because the & symbol would be converted AFTER the < character was converted (or any other character for that matter)
- I fixed the problem by moving the line:
- <pre><code>
- entities['38'] = '&amp;';
- </code></pre>
- near the top of the html_translation_table() function,
- right above the the following line:
- <pre><code>
- if (useTable === 'HTML_ENTITIES') {
- </code></pre>
- This would make sure that the & characters is converted first, then the rest of the charachters would be converted.
- -Frank Forte
- <hr />
- <strong>
- Roland Hentschel
- </strong>
- on 2009-06-30 08:32:41 <br />
- An implementation for this script:
- http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_chr/
- <pre><code>
- function charmap(font) {
- document.write("<style>\n*{font-family:"
- +font+"; font-size:24pt;}\n</style>\n");
- document.write("<table>\n");
- for (x=0;x<16;x++) {
- document.write("<tr>\n");
- for (y=0;y<16;y++) {
- document.write("<td>"+chr(16*x+y)+"</td>\n");
- }
- document.write("</tr>\n");
- }
- document.write("</table>\n");
- }
- </code></pre>
- <hr />
- <strong>
- <a href="http://bahai-library.com" rel="nofollow">Brett Zamir</a>
- </strong>
- on 2009-05-30 05:37:10 <br />
- Kevin fixed it in SVN...Thanks for the reports!
- <hr />
- <strong>
- <a href="www.carrot.org" rel="nofollow">Jason Wang</a>
- </strong>
- on 2009-05-29 09:36:38 <br />
- There is a bug for the function. For example, when using PHP strtr("abc","abc","cba") the result is "cba". But using this function, the result is "aba". Because the first character "a" is replaced by "c", however it became "a" when trying to replace all character "c" with "a". Maybe here we can use some array to store the status as well the chars in order to solve the problem.
- Good Luck
- <hr />
- <strong>
- uestla
- </strong>
- on 2009-03-10 13:35:01 <br />
- In PHP the function strtr() called with three arguments (string, from, to) replaces the characters in the whole string. Shouldn't be the global modificator 'g' in your script?
- Thanks for your answer, uestla (sorry for my english).
- <hr />