Created
April 17, 2015 15:38
-
-
Save mcaskill/4f91db18f9c4cf2e386b to your computer and use it in GitHub Desktop.
WordPress \ Formatting : Prepends a leading slash and removes leading forward slashes and backslashes if they exist.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Prepends a leading slash. | |
* | |
* Will remove leading forward and backslashes if it exists already before adding | |
* a leading forward slash. This prevents double slashing a string or path. | |
* | |
* The primary use of this is for paths and thus should be used for paths. It is | |
* not restricted to paths and offers no specific path support. | |
* | |
* Opposite of {@see WordPress\trailingslashit()}. | |
* | |
* @param string $string What to add the leading slash to. | |
* @return string String with leading slash added. | |
*/ | |
function leadingslashit( $string ) | |
{ | |
return '/' . unleadingslashit( $string ); | |
} | |
/** | |
* Removes leading forward slashes and backslashes if they exist. | |
* | |
* The primary use of this is for paths and thus should be used for paths. It is | |
* not restricted to paths and offers no specific path support. | |
* | |
* Opposite of {@see WordPress\untrailingslashit()}. | |
* | |
* @param string $string What to remove the leading slashes from. | |
* @return string String without the leading slashes. | |
*/ | |
function unleadingslashit( $string ) | |
{ | |
return ltrim( $string, '/\\' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment