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

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: anchor() unable to parse double quotes (/showthread.php?tid=3682)



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>