修复使用包含颚化符(~)的URL时的脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了修复使用包含颚化符(~)的URL时的脚本相关的知识,希望对你有一定的参考价值。

If you are using the [TimThumb](http://code.google.com/p/timthumb/ "TimThumb on Google Code") script with a URL the contains tildes (~) and images are breaking, here is the fix...

I did not create this snippet but found it extremely useful so I thought I'd make it available here. The URL listed is not mine but where I found it. Enjoy :-)

At line 209 (as of 01-29-13) in the script you will find the following line of code:

`$this->src = $this->param('src');`

Replace that line with the following snippet:
  1. //check if tilde is found in src
  2. if(strstr($this->param('src'),'~'))
  3. {
  4. $url_parts = explode('/',$this->param('src'));
  5.  
  6. foreach($url_parts as $url_part)
  7. {
  8. //do not include any part with a ~ when building new url
  9. if(!strstr($url_part,'~'))
  10. {
  11. $new_dev_url .= $url_part.'/';
  12. }
  13. }
  14.  
  15. //remove trailing slash
  16. $new_dev_url = substr($new_dev_url,0,-1);
  17.  
  18. $this->src = $new_dev_url;
  19. }
  20. else
  21. {
  22. $this->src = $this->param('src');
  23. }

以上是关于修复使用包含颚化符(~)的URL时的脚本的主要内容,如果未能解决你的问题,请参考以下文章

分享前端开发常用代码片段

使用带有 viewpager 的异步任务时的竞争条件

收藏|分享前端开发常用代码片段

关于js----------------分享前端开发常用代码片段

IE6 中 jQuery 对话框的修复或解决方法 - 对话框包含表单时的主要布局问题

修复 CoordinatorLayout 中的底栏