CodeIgniter Forums

Full Version: anchor() unable to parse double quotes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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>