dou91855 2013-01-15 12:51
浏览 78
已采纳

Code Igniter auto_link()弄乱了我的电子邮件地址

Using auto_link() to output the copy from a CMS controlled page onto the front end. I have 2 email addresses, recruit@ and bankrecruit@ in the stored copy.

When I look at the front end the first email, recruit@, is auto_linked to become a linked email address but the second one becomes bank followed by the recruit@ email link. This is obviously not what I expected.

auto_link() is matching all cases of recruit@ in which case the bankrecruit@ is being converted as it finds recruit@ first and converts that.

If I remove the recruit@ then bankrecruit@ works fine. Also if I change the name to bank@ then both addresses work as expected.

Is there a resolution for this?

<p>This is the address a@test.com</p>
<p>This is the second address ba@test.com</p>

And the script is:

auto_link($content)
  • 写回答

1条回答 默认 最新

  • douhu8851 2013-01-15 14:58
    关注

    As @cryptic pointed, it is a bug in the auto_link method. (See source) They are finding all email address in the output and then, they do a replace all (str_replace) with the anchored version. So...

    <p>This is the address a@test.com</p>
    <p>This is the second address ba@test.com</p>
    

    becomes

    <p>This is the address <a ...>a@test.com</a></p>
    <p>This is the second address b<a ...>a@test.com</a></p>
    

    on first pass for the email a@test.com. On the second e-mail, they try to replace ba@test.com with the anchored version, but the str_replace can not find the address, it has already been replaced.

    You could implement your own fix by :

    1. Extending the auto_link method of the URL helper. See documentation
    2. Copy the auto_link method from the CodeIgniter source into that new Helper.
    3. Replace only the first occurrence of the string. See this SO thread.

    For example:

    $str = str_replace($matches['0'][$i], safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str);
    

    becomes

    $str = preg_replace('/' . $matches['0'][$i] . '/', safe_mailto($matches['1'][$i].'@'.$matches['2'][$i].'.'.$matches['3'][$i]).$period, $str, 1);
    

    That should fix it for you. I would advise against modifying the system's URL_Helper, you might run into some migration problems later on.

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘