PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/_octopress/source/functions/strtr/_comments.html

https://github.com/evangelia-mitsopoulou/phpjs
HTML | 316 lines | 248 code | 67 blank | 1 comment | 0 complexity | ee12407c0acbd67477fec1e96a8a8c1a MD5 | raw file
  1. <!-- Generated by Rakefile:build -->
  2. <strong>
  3. <a href="http://an3m1.com/" rel="nofollow">????? ????????</a>
  4. </strong>
  5. on 2012-04-10 09:52:43 <br />
  6. 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 youve said and still make it interesting
  7. <hr />
  8. <strong>
  9. Theriault
  10. </strong>
  11. on 2011-05-13 10:28:09 <br />
  12. @Breton: I can't verify it because I don't have IE9, but my guess on a fix would be changing line 55 from...
  13. <pre><code>
  14. tmpFrom.push(fr);
  15. </code></pre>
  16. to...
  17. <pre><code>
  18. tmpFrom.push('' + fr);
  19. </code></pre>
  20. Let us know if this fixes it.
  21. <hr />
  22. <strong>
  23. Breton
  24. </strong>
  25. on 2011-05-10 11:24:02 <br />
  26. Hi, there is a new bug in IE9 with the function strtr !
  27. This line doesn't work : &quot;if (str.substr(i, from[j].length) == from[j]) {&quot;
  28. Have you got any idea ?
  29. You can see the error here : http://imageshack.us/photo/my-images/805/bugc.jpg/
  30. Fucking IE ! ^^'
  31. <hr />
  32. <strong>
  33. <a href="http://preseka.mygamesonline.com" rel="nofollow">odin</a>
  34. </strong>
  35. on 2011-03-27 23:45:26 <br />
  36. Hey i maid even bether one look down:
  37. it contanis 0 loops for norma use and 1 loop for advanced use
  38. <pre><code>
  39. function strtr(s,f,t)
  40. {
  41. core=function(str,from,to){//core function
  42. str=str.split(from);//breake parts that we wan't to
  43. str=str.join(to);//glue with new parts that we wan't to
  44. return str;
  45. };//end of core function
  46. if(!t){//check if we use advanced option
  47. r=s;
  48. for(e in f){//loop
  49. r=core(r,e,f[e]);//call our core function
  50. }
  51. return r;// end code and retun value
  52. }
  53. //normal use
  54. return core(s,f,t); // just call normal core function and return
  55. }
  56. /*
  57. example:
  58. normal use:
  59. strtr(&quot;This string is string.&quot;,&quot;string&quot;,&quot;text&quot;);
  60. =This text is text.
  61. advanced use
  62. strtr(&quot;This string is texty.&quot;,{'texty':'text','string':'text'});
  63. =This text is string.
  64. advanced use WARNING!
  65. strtr(&quot;This string is text.&quot;,{'text':'string','string':'text'});
  66. =This text is text.
  67. this is not switcher it's replacer!!
  68. */
  69. </code></pre>
  70. <hr />
  71. <strong>
  72. <a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a>
  73. </strong>
  74. on 2010-12-02 09:55:47 <br />
  75. @Robert: Please try your function against the existing examples to make sure it works. Thanks...
  76. <hr />
  77. <strong>
  78. Robert
  79. </strong>
  80. on 2010-12-01 20:41:28 <br />
  81. What about something more like this? I saw an example of using this for urlencode and thought it would work well for strtr.
  82. <pre><code>
  83. function strtr(base, old, n){
  84. return base.replace(/[A-Za-z0-9_.-]/g, function (s) {
  85. for (var k = 0; k &lt; old.length; k++) {
  86. if (s == old.charAt(k) &amp;&amp; k &lt; n.length) {
  87. return n.charAt(k);
  88. }
  89. }
  90. });
  91. }
  92. </code></pre>
  93. <hr />
  94. <strong>
  95. jpfle
  96. </strong>
  97. on 2009-12-11 16:20:54 <br />
  98. @Brett: it works very great now. Thanks again! :-)
  99. <hr />
  100. <strong>
  101. <a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a>
  102. </strong>
  103. on 2009-12-11 12:40:42 <br />
  104. @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
  105. <hr />
  106. <strong>
  107. jpfle
  108. </strong>
  109. on 2009-12-11 04:25:40 <br />
  110. @Brett: Thanks for your answer. However, it no longer works neither on Firefox nor IE. Here's what I packaged on phpjs.org:
  111. - `i18n_loc_get_default()`
  112. - `i18n_loc_set_default()`
  113. - `ini_set()`
  114. - `krsort()`
  115. - `strtr()`
  116. and then I replaced `strtr()` by github's version. With the same code of my previous comment, &quot;ça et là&quot; is output on Firefox and IE without any translation, namely &quot;ça et là&quot;. Firefox's Error Console is empty.
  117. <hr />
  118. <strong>
  119. <a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a>
  120. </strong>
  121. on 2009-12-10 05:42:56 <br />
  122. @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).
  123. <hr />
  124. <strong>
  125. jpfle
  126. </strong>
  127. on 2009-12-09 22:30:16 <br />
  128. 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 ('à' =&gt; 'a', 'é' =&gt; 'e', 'î' =&gt; 'i', etc.) with strstr() to create an anchor. However, there's a bug with Internet Explorer 6. Take this code:
  129. <pre><code>
  130. var texte = 'çà et là';
  131. texte = strtr(texte, {'ç': 'c', 'à': 'a', ' ': '-'});
  132. alert(texte);
  133. </code></pre>
  134. Firefox (3.5.5) outputs &quot;ca-et-la&quot;, as expected, but IE6 outputs &quot;ca-undefinedundefined-undefineda&quot;.
  135. <hr />
  136. <strong>
  137. kwemart
  138. </strong>
  139. on 2009-11-20 12:10:58 <br />
  140. @kevin van
  141. yes I know my function is just for regulars expressions
  142. it wouldn't work with ayyay but I'll update it later
  143. cheer .
  144. <hr />
  145. <strong>
  146. <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
  147. </strong>
  148. on 2009-11-07 18:50:03 <br />
  149. @ kwemart: Thanks for sharing. However with your code, only the 3rd example produces the expected output. The other ones fail :(
  150. <hr />
  151. <strong>
  152. kwemart
  153. </strong>
  154. on 2009-10-31 12:25:41 <br />
  155. hi this function is very nice but I propose an other solution , it only work with a regular expression.
  156. <pre><code>
  157. function strtr(str,from,to)
  158. {
  159. var patt=str.split(from),str2=&quot;&quot;;
  160. var l=patt.length,i=1;
  161. while(i&lt;=l-1){str=str.replace(from,to);i+=1;}
  162. return str;
  163. }
  164. </code></pre>
  165. <hr />
  166. <strong>
  167. <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
  168. </strong>
  169. on 2009-07-03 13:52:01 <br />
  170. @ Roland Hentschel: Thanks for sharing
  171. @ Frank Forte &amp; T.Wild: Cool, let's continue at the page suggested by T.Wild
  172. <hr />
  173. <strong>
  174. T.Wild
  175. </strong>
  176. on 2009-07-02 22:59:55 <br />
  177. @Frank Forte
  178. You may want to post your problem over at
  179. http://phpjs.org/functions/htmlspecialchars
  180. rather than here on strtr
  181. <hr />
  182. <strong>
  183. <a href="http://thenetgen.com/" rel="nofollow">Frank Forte</a>
  184. </strong>
  185. on 2009-07-02 15:25:46 <br />
  186. I found the following error with the htmlspecialchars() function when doing the following:
  187. <pre><code>
  188. el.innerHTML = htmlspecialchars('test 1 &lt; 2 ');
  189. </code></pre>
  190. The output (inserted into the element) was
  191. 'test 1 &amp;lt; 2'
  192. The htmlspecialchars function does this:
  193. step 1 &lt; turns to &amp;lt;
  194. step 2 &amp;lt; turns to &amp;amp;lt;
  195. This is because the &amp; symbol would be converted AFTER the &lt; character was converted (or any other character for that matter)
  196. I fixed the problem by moving the line:
  197. <pre><code>
  198. entities['38'] = '&amp;amp;';
  199. </code></pre>
  200. near the top of the html_translation_table() function,
  201. right above the the following line:
  202. <pre><code>
  203. if (useTable === 'HTML_ENTITIES') {
  204. </code></pre>
  205. This would make sure that the &amp; characters is converted first, then the rest of the charachters would be converted.
  206. -Frank Forte
  207. <hr />
  208. <strong>
  209. Roland Hentschel
  210. </strong>
  211. on 2009-06-30 08:32:41 <br />
  212. An implementation for this script:
  213. http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_chr/
  214. <pre><code>
  215. function charmap(font) {
  216. document.write(&quot;&lt;style&gt;\n*{font-family:&quot;
  217. +font+&quot;; font-size:24pt;}\n&lt;/style&gt;\n&quot;);
  218. document.write(&quot;&lt;table&gt;\n&quot;);
  219. for (x=0;x&lt;16;x++) {
  220. document.write(&quot;&lt;tr&gt;\n&quot;);
  221. for (y=0;y&lt;16;y++) {
  222. document.write(&quot;&lt;td&gt;&quot;+chr(16*x+y)+&quot;&lt;/td&gt;\n&quot;);
  223. }
  224. document.write(&quot;&lt;/tr&gt;\n&quot;);
  225. }
  226. document.write(&quot;&lt;/table&gt;\n&quot;);
  227. }
  228. </code></pre>
  229. <hr />
  230. <strong>
  231. <a href="http://bahai-library.com" rel="nofollow">Brett Zamir</a>
  232. </strong>
  233. on 2009-05-30 05:37:10 <br />
  234. Kevin fixed it in SVN...Thanks for the reports!
  235. <hr />
  236. <strong>
  237. <a href="www.carrot.org" rel="nofollow">Jason Wang</a>
  238. </strong>
  239. on 2009-05-29 09:36:38 <br />
  240. There is a bug for the function. For example, when using PHP strtr(&quot;abc&quot;,&quot;abc&quot;,&quot;cba&quot;) the result is &quot;cba&quot;. But using this function, the result is &quot;aba&quot;. Because the first character &quot;a&quot; is replaced by &quot;c&quot;, however it became &quot;a&quot; when trying to replace all character &quot;c&quot; with &quot;a&quot;. Maybe here we can use some array to store the status as well the chars in order to solve the problem.
  241. Good Luck
  242. <hr />
  243. <strong>
  244. uestla
  245. </strong>
  246. on 2009-03-10 13:35:01 <br />
  247. 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?
  248. Thanks for your answer, uestla (sorry for my english).
  249. <hr />