For some reason str_replace()
does not work with /
. I am creating a function to accept a unique linking style in input and text area forms for a blog CMS that I am making. For instance, [{http://brannondorsey.com}My Website]
will be translated to <a href='http://brannondorsey.com'>My Website</a>
when passed through make_link($string);
. Here is my code:
function make_link($input){
$double = str_replace( '"', '"', $input);
$single = str_replace("'", "'", $double);
$bracket_erase = str_replace('[', "", $single);
$link_open = str_replace('{', '<a href="', $bracket_erase);
$link_close = str_replace("}", ">", $link_open);
$link_value = str_replace(']', "</a>", $link_close);
echo $link_value;
}
Everything works correctly except for ]
is not replaced with </a>
. If I remove the slash it will successfully replace ]
with <a>
, however, as we all know, that does not properly close an anchor tag and therefor makes all html content between the {
and the next closing anchor tag in my webpage a link.