Search code examples
phphyperlinkpreg-replacemeta-tags

Preg_Replace links in a text like facebook


How can I convert a link in a text: sdgf sdg https://www.google.ch/ dgsd dfg

Into this: Click here to view the image

Similar to Facebook


Solution

  • try this

    $result = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "\\2", $string);