src/System/Helpersurl_helper.php

CodeIgniter

An open source application development framework for PHP

This content is released under the MIT License (MIT)

Copyright (c) 2014-2019 British Columbia Institute of Technology Copyright (c) 2019 CodeIgniter Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Functions

site_url()

site_url(mixed  $uri = '', string|null  $protocol = null, \Config\App|null  $altConfig = null) : string

Return a site URL to use in views

Parameters

mixed $uri

URI string or array of URI segments

string|null $protocol
\Config\App|null $altConfig

Alternate configuration to use

Returns

string

base_url()

base_url(mixed  $uri = '', string  $protocol = null) : string

Return the base URL to use in views

Parameters

mixed $uri

URI string or array of URI segments

string $protocol

Returns

string

current_url()

current_url(boolean  $returnObject = false) : string|\CodeIgniter\HTTP\URI

Current URL

Returns the full URL (including segments) of the page where this function is placed

Parameters

boolean $returnObject

True to return an object instead of a strong

Returns

string|\CodeIgniter\HTTP\URI

previous_url()

previous_url(boolean  $returnObject = false) : \CodeIgniter\HTTP\URI|mixed|string

Returns the previous URL the current visitor was on. For security reasons we first check in a saved session variable, if it exists, and use that.

If that's not available, however, we'll use a sanitized url from $_SERVER['HTTP_REFERER'] which can be set by the user so is untrusted and not set by certain browsers/servers.

Parameters

boolean $returnObject

Returns

\CodeIgniter\HTTP\URI|mixed|string

uri_string()

uri_string() : string

URL String

Returns the path part of the current URL

Returns

string

index_page()

index_page(\Config\App|null  $altConfig = null) : string

Index page

Returns the "index_page" from your config file

Parameters

\Config\App|null $altConfig

Alternate configuration to use

Returns

string

anchor()

anchor(mixed  $uri = '', string  $title = '', mixed  $attributes = '', \Config\App|null  $altConfig = null) : string

Anchor Link

Creates an anchor based on the local URL.

Parameters

mixed $uri

URI string or array of URI segments

string $title

The link title

mixed $attributes

Any attributes

\Config\App|null $altConfig

Alternate configuration to use

Returns

string

anchor_popup()

anchor_popup(string  $uri = '', string  $title = '', mixed  $attributes = false, \Config\App|null  $altConfig = null) : string

Anchor Link - Pop-up version

Creates an anchor based on the local URL. The link opens a new window based on the attributes specified.

Parameters

string $uri

the URL

string $title

the link title

mixed $attributes

any attributes

\Config\App|null $altConfig

Alternate configuration to use

Returns

string

mailto()

mailto(string  $email, string  $title = '', mixed  $attributes = '') : string

Mailto Link

Parameters

string $email

the email address

string $title

the link title

mixed $attributes

any attributes

Returns

string

safe_mailto()

safe_mailto(string  $email, string  $title = '', mixed  $attributes = '') : string

Encoded Mailto Link

Create a spam-protected mailto link written in Javascript

Parameters

string $email

the email address

string $title

the link title

mixed $attributes

any attributes

Returns

string

auto_link()

auto_link(string  $str, string  $type = 'both', boolean  $popup = false) : string

Auto-linker

Automatically links URL and Email addresses. Note: There's a bit of extra code here to deal with URLs or emails that end in a period. We'll strip these off and add them after the link.

Parameters

string $str

the string

string $type

the type: email, url, or both

boolean $popup

whether to create pop-up links

Returns

string

prep_url()

prep_url(string  $str = '') : string

Prep URL - Simply adds the http:// part if no scheme is included.

Formerly used URI, but that does not play nicely with URIs missing the scheme.

Parameters

string $str

the URL

Returns

string

url_title()

url_title(string  $str, string  $separator = '-', boolean  $lowercase = false) : string

Create URL Title

Takes a "title" string as input and creates a human-friendly URL string with a "separator" string as the word separator.

Parameters

string $str

Input string

string $separator

Word separator (usually '-' or '_')

boolean $lowercase

Whether to transform the output string to lowercase

Returns

string