Reputation: 662
I need to change this code:
$output = preg_replace("#<a ([^>]*)>([^<]*)<\/a>#", "<a href=\"$1\">$2</a>", $output)
to make from <a some.url>description</a>
to HTML code <a href="some.url">description</a>
, but after i changed < and >
to < and >
it doesn't make what I wanted.
Thank you for your help.
EDIT:
I wouldn't use html_entity_decode()
, because I want this for enabling slightly simplified HTML tags, but the most of HTML i would have disabled.
Input for my function is a variable, obtained from a form:
Firstly the code replaces all <
and >
with <
and >
.
Than it changes back some text-modifying static HTML tags, for example <b>
and </b>
.
But in the end, i want to change every link inputed as <a some.url>link</a>
(and than by code changed to <a some.url>link</a>
) to be changed by preg_replace()
into standard HTML code <a href="some.url">link</a>
Upvotes: 1
Views: 2205
Reputation: 4725
http://php.net/manual/en/function.html-entity-decode.php
$str = "this 'quote' is <b>bold</b>"
html_entity_decode($output)
// output This 'quote' is <b>bold</b>
http://php.net/manual/en/function.htmlentities.php
$str = "This 'quote' is <b>bold</b>";
htmlentities($output);
// output this 'quote' is <b>bold</b>
Upvotes: 2