doutingyou2198 2018-12-11 20:10
浏览 50

Smarty模板引擎 - regex_replace任意电话号码与自定义HTML

My cms system (flynax.com) uses smarty template engine.

I have template that prints field value from database.

Tag used in template to print description field value (html) is:

{$item.value}

I need to hide any phone number from description field, and to do that I need to find any phone number in field output and replace it with this code:

<span class='telefon' data-last='REPLACED_VALUE'><span class='telefon2'>{$lang.click_here_to_show}</span></span>

I have jquery code that will be used to hide any phone number and show it on click (I also than track clicks with google analytics).

    {literal}

<script>
    $(document).ready(function() {
      $('.telefon').toggle(function() {
     $(this).find('span').text({/literal}'{$lang.click_here_to_show}'{literal});
      }, function() {
        $(this).find('span').text($(this).data('last'));
      }).click();
    });
  </script>
{/literal}

Code that I am trying and which trows me errors is:

{$item.value|regex_replace:"/([+]{0,1}[\d]{1,5}[\s]{0,1}[\/]{0,1}[(]{0,1}[\d]{0,3}[)]{0,1}\s{0,1}\d{2,4}[-]{0,1}[\s]{0,1}[\d]{2,4}[-]{0,1}[\s]{0,1}[\d]{1,4})$/gm":"<span class='telefon' data-last='$1'><span class='telefon2'>{$lang.click_here_to_show}</span></span>"}

test of my regex: check here

Can you suggest what I am doing wrong?

Thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Oracle触发器记录修改前后的字段值
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器