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条)

报告相同问题?