anchor()

anchor($uri = '', $title = '', $attributes = '')

Parameters:
  • $uri (string) – URI string
  • $title (string) – Anchor title
  • $attributes (mixed) – HTML attributes
Returns:

HTML hyperlink (anchor tag)

Return type:

string

Creates a standard HTML anchor link based on your local site URL.

The first parameter can contain any segments you wish appended to the URL. As with the site_url() function above, segments can be a string or an array.

Note

If you are building links that are internal to your application do not include the base URL (http://...). This will be added automatically from the information specified in your config file. Include only the URI segments you wish appended to the URL.

The second segment is the text you would like the link to say. If you leave it blank, the URL will be used.

The third parameter can contain a list of attributes you would like added to the link. The attributes can be a simple string or an associative array.

Here are some examples:

echo anchor('news/local/123', 'My News', 'title="News title"');
// Prints: <a href="http://example.com/index.php/news/local/123" title="News title">My News</a>

echo anchor('news/local/123', 'My News', array('title' => 'The best news!'));
// Prints: <a href="http://example.com/index.php/news/local/123" title="The best news!">My News</a>

echo anchor('', 'Click here');
// Prints: <a href="http://example.com">Click Here</a>
doc_CodeIgniter
2016-10-15 16:30:51
Comments
Leave a Comment

Please login to continue.