D
D
Dmitry2018-02-12 12:58:39
PHP
Dmitry, 2018-02-12 12:58:39

Why might htmlspecialchars_decode not work?

The situation is this:
I am writing my ticket system for the user's personal account. I accept the text of the message from the user,
convert the inserted links into clickable ones, and then convert the html tags into HTML entities.

$text = preg_replace("/\b((http(s?):\/\/)|(www\.))([\w\.]+)([\/\w+\.]+)([\?\w+\.\=]+)([\&\w+\.\=]+)\b/i", "<a href=\"http$3://$4$5$6$7$8\" target=\"_blank\">$2$4$5$6$7$8</a>", $text);
$text = htmlspecialchars($text);

the data gets into mysql DB
When I display messages in a loop, before printing out the $text variable, I process it with the htmlspecialchars_decode() function;
but unfortunately, when I open the source code of the page with the list of messages, I see:
&lt;a href=&quot;https://vk.com/&quot; target=&quot;_blank&quot;&gt;https://vk.com/&lt;/a&gt;

Explain to me, stupid, why they don’t convert back and how to make links clickable then?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question