The scenario is:
htmlentities()
.And when output to a webpage it shows like this (and the link is shown as plain text as well)
Hello there, how are you today.
This text is saved and I want to show links,
but the links are displayed like this: <a href="text">text</a>.
(because the html surrounding the link are < and >)
I've made it like this (plain text only) because I don't want users to mess up the the content with HTML tags etc.
Is it possible to replace >
and <
into < and > but only when there is a link? I'm not sure how to achieve this.
UPDATE:
A thought might be using a custom tag like [mylink]actual link[/mylink]
. It would be OK as well. This might be a better solution? What are your thoughts?
答案 0 :(得分:2)
Instead of using htmlentities
use strip_tags:
strip_tags — Strip HTML and PHP tags from a string
There is an option that allows to ignore certain tags. In your example:
$text="This <b>is</b> a <a href='#'>test</a>";
echo strip_tags($text,'<a>');
That will remove every HTML tag but the anchors.