<?php $re = '/\[@url\|([^|]+)\|(\d+)\](?=(?>.*\R+)+^\[\2]:\s+(\S+))|^\[\d+]:\h+\S+/m'; $str = 'We have [@url|first url|1] and the [@url|the second url|2] and then [@url|the third url|3] [1]: https://www.google.com [2]: www.facebook.com [3]: http://www.amazon.com'; echo preg_replace_callback($re, function($match) { if (isset($match[1])) { return "<a href=\"{$match[3]}\">{$match[1]}</a>"; } }, $str);
You have javascript disabled. You will not be able to edit any code.