I have a strings of the form
\"Look at this [website]{http://www.stackoverflow.com}
or at this [page]{http://www.google.com}\"
and I want
This can be made easily by using preg_replace
:
$pattern = "/(\\[([^\\]]+)\\]\\{([^\\}]+)\\})/";
$replacement = '<a href="$3">$2</a>';
$finalStr = preg_replace($pattern, $replacement, $yourString);
try it with preg_replace
$str="Look at this [website]{http://www.stackoverflow.com} or at this [page]{http://www.google.com}";
echo preg_replace('/\[(.*?)\]\{(.*?)\}/', "<a href='$2'>$1</a>", $str);
output:
Look at this <a href='http://www.stackoverflow.com'>website</a> or at this <a href='http://www.google.com'>page</a>
working Example: https://3v4l.org/jLbff