Skip to content

Instantly share code, notes, and snippets.

@brianlayman
Created August 19, 2016 14:57
Show Gist options
  • Save brianlayman/b43e82e61b2fc67829cab6565684d839 to your computer and use it in GitHub Desktop.
Save brianlayman/b43e82e61b2fc67829cab6565684d839 to your computer and use it in GitHub Desktop.
trailingampit ensures a URL ends with a /amp/
<?php
/**
* Ensures the passed text, presumably an url, ends with '/amp/'
*/
if ( !function_exists( 'trailingampit' ) ) {
function trailingampit( $string ) {
return untrailingampit( $string ) . 'amp/';
}
}
/**
* Ensures the passed text, presumably an url, does not end with 'amp/' or 'amp'
*/
if ( !function_exists( 'untrailingampit' ) ) {
function untrailingampit( $str ) {
$result = preg_replace( '/(amp|amp\/)$/', '', $str );
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment