duannian3494 2016-11-20 10:18
浏览 55
已采纳

一个数组字符串中的多个匹配

I'm trying to match ^Description^*http://google.com* and convert into URL. It's working with JS, but I don't know how implement this into PHP Array. My JS looks like this:

var that = $(this);
    var vid = that.html().match(/\^(.*)\^/gm); 
    var vid2 = that.html().match(/\*(.*)\*/gm);
    var vid2 = jQuery.trim(vid2).slice(1,-1);
    var vid1 = jQuery.trim(vid).slice(1,-1);
     that.html(function(i, h) {
        return h.replace(/\^(.*)\^\*(.*)\*/gm, '<a target="_blank" href="'+vid2+'">'+vid1+'</a>');
    });

And my PHP Array:

$find = array('/\*\*([^*]+)\*\*/', '/@(\\w+)/');
$replace = array('<span style="font-weight:bold">$1</span>', '<a href=/profile/$1>@$1</a>');
$result = preg_replace($find, $replace, $comment_text);
  • 写回答

2条回答 默认 最新

  • doujiaochan7317 2016-11-20 10:45
    关注

    I've done with that :)

    $find = array('/\*\*([^*]+)\*\*/', '/@(\\w+)/', '/\^(.*)\^\*(.*)\*/');
    $replace = array('<span style="font-weight:bold">$1</span>', '<a href=/profile/$1>@$1</a>','<a target="_blank" href="$2">$1</a>');
    $result = preg_replace($find, $replace, $comment_text);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程