-2

Per exampe for:

<a href="http://www.google.com">http://www.google.com</a>

convert to

http://www.google.com

in plain text not hyperlink using preg_replace in php.

Andrés Morales
  • 793
  • 7
  • 20

2 Answers2

0

You must use the following code:

$content = '<a href="http://www.google.com">http://www.google.com</a>';
$unlinked_content = preg_replace('#<a.*?>(.*?)</a>#is', '$1', $content);

I used the 's' modifier for multilined links.

But if you are trying to create an legible piece of text you must to encapsulate the unlinked content using something like [$1] as the second parameter of preg_replace function.

If you want to learn about regex, I recomend the regex101 page.

Andrés Morales
  • 793
  • 7
  • 20
-1
preg_replace('#<a.*?>(.*?)</a>#i', '\1', $text)

How to remove a link from content in php?

Community
  • 1
  • 1
zeflex
  • 1,487
  • 1
  • 14
  • 29