Skip to content

Instantly share code, notes, and snippets.

@joshuadavidnelson
Last active December 21, 2015 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuadavidnelson/6247036 to your computer and use it in GitHub Desktop.
Save joshuadavidnelson/6247036 to your computer and use it in GitHub Desktop.
Check for and, if not there, add quotation marks to a string
/**
*
* Return string with quotation marks
*
* @author Joshua Nelson
* @link http://joshuadnelson.com
*
*/
function jdn_add_quotation( $string ) {
if( !empty( $string ) ) {
if( $string[0] == '"' && $string[strlen($string)-1] == '"' ) {
return $string;
} elseif( $string[0] == '"' && $string[strlen($string)-1] != '"' ) {
$string = $string . '"';
} elseif( $string[0] != '"' && $string[strlen($string)-1] == '"' ) {
$string = '"' . $string;
} else {
$string = '"' . $string . '"';
}
}
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment