user3197354 user3197354 - 1 year ago 50
PHP Question

Extracting link from a href and putting it within brackets

I have searched and couldn't find what I was looking for.

This is how it will normally be:

Hi how are you? Have you checked <a href="">Google</a> or <a href="">YouTube</a>?

But what I would love to have, because I'm willing to apply this on a print or PDF page is the following:

Hi how are you? Have you checked <a href="">Google</a> (<a href=""></a>)
or <a href="">YouTube</a> (<a href=""></a>)?

Now, I understand that there should be some work with regex, but I don't know how to use that. The text will be taken from the variable $content which has the article in it, and what I would like to have is that all links within $content remain as they are plus the content of href be as an additional hyperlink within brackets "()" so that, hypothetically when someone reads a printed article where hyperlinks are they would be able to see the actual URL.


Use a pseudo element to add the href after your links, something like:

    content: " (" attr(href) ") ";