URL Helpers

The URL Helpers are lightweight functions that simplify URL handling in PHP. They provide utilities for retrieving current and previous URLs, extracting segments, generating anchor tags with automatic base URL resolution, performing redirects, and cleaning query strings to streamline navigation and linking in your applications.

anchor()

Generates an anchor (<a>) tag with optional attributes and partial XSS protection.

current_url()

Get the current URL of the web page.

get_last_segment()

Retrieves the value of the last segment of the current URL. It extracts the last segment by utilizing the 'get_last_part' function, which splits the URL by '/' and returns the last element.

get_num_segments()

Retrieves the number of segments in the current URL after the base URL. It calculates the number of segments by removing the base URL and then splitting the remaining path into segments using '/' as the delimiter.

previous_url()

Retrieves the URL of the previous page, if available.

redirect()

Perform an HTTP redirect to the specified URL.

remove_query_string()

Remove query string from a URL.

segment()

Retrieves a specific segment from the current URL. Unlike earlier framework conventions that implicitly injected URL values into controller methods, segment() makes URL input explicit, predictable, and secure.