0

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);
Szmerd
  • 499
  • 1
  • 4
  • 13

2 Answers2

0

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);
Szmerd
  • 499
  • 1
  • 4
  • 13
0

To match the regular experession ^Description^*http://google.com* in PHP you could use the /s modifier (as described here) instead of the ^ in the middle of the Regex. I tested the code here.

<?php
$find = array('/^Description.*\*(.*)\*/s');
$replace = array('<a href="$1">$1</a>');
$comment_text = 'Description 
*http://google.de*';
$result = preg_replace($find, $replace, $comment_text);
echo $result;
Community
  • 1
  • 1
Martin Cup
  • 2,399
  • 1
  • 21
  • 32