I'm trying to parse something like this
{%github user/repo %}
Into
<a href="https://github.com/user/repo">Repo</a>
This method also should be secure ex: Look below my function.
function parseliquid($string)
{
$randhashtoreplace = md5(rand(0, 9999));
$regexp = '/\{%github (.*?)%\}/';
$str = preg_replace($regexp, $randhashtoreplace, $string);
preg_match($regexp, $string, $matches);
return $matches;
}
var_dump(parseliquid("## Hello {%github isn't/safe {%github repo/user %} %}"));
Now the expected output is
array(2) {
[0]=>
string(41) "{%github isn't/safe {%github repo/user %}"
[1]=>
string(9) "repo/user"
}
but the output that comes is
array(2) {
[0]=>
string(41) "{%github isn't/safe {%github repo/user %}"
[1]=>
string(30) "isn't/safe {%github repo/user "
}
Now what have I done wrong?