Last active
December 21, 2015 04:08
-
-
Save joshuadavidnelson/6247036 to your computer and use it in GitHub Desktop.
Check for and, if not there, add quotation marks to a string
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
/** | |
* | |
* 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