CodeIgniter Forums
anchor() unable to parse double quotes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: anchor() unable to parse double quotes (/thread-3682.html)



anchor() unable to parse double quotes - El Forum - 10-16-2007

[eluser]Armchair Samurai[/eluser]
Pretty minor, but has come up a few times in the forum, mostly from people wanting to use the anchor() fuction with an image.

The anchor() function is unable to parse double quotes in the text parameter, causing corrupted HTML output, unless the third parameter is present to prevent the default rendering of the title attribute.

Example:
Code:
<?=anchor('path/goes/here', '"foo"');?>

/* Outputs an messy link */
<a href="http://docroot/path/goes/here" title=""foo"">"foo"</a>

One solution would be to parse the $attributes variable on line 111:
Code:
/* in the URL helper */
$attributes = str_replace('"', '&quot;', $title);

/* if you call the code from the first example,
it will parse everything correctly, outputting: */
<a href="http://docroot/path/goes/here" title="&quot;foo&quot;">"foo"</a>