; } /** * Returns the string after all HTML entities have been decoded. * * @since 1.0.0 * * @param string $string The string to decode. * @return string The decoded string. */ public function decodeHtmlEntities( $string ) { static $decodeHtmlEntities = []; if ( isset( $decodeHtmlEntities[ $string ] ) ) { return $decodeHtmlEntities[ $string ]; } // We must manually decode non-breaking spaces since html_entity_decode doesn't do this. $string = $this->pregReplace( '/ /', ' ', $string ); $decodeHtmlEntities[ $string ] = html_entity_decode( (string) $string, ENT_QUOTES ); return $decodeHtmlEntities[ $string ]; } /** * Returns the string with script tags stripped. * * @since 1.0.0 * * @param string $string The string. * @return string The modified string. */ public function stripScriptTags( $string ) { static $stripScriptTags = []; if ( isset( $stripScriptTags[ $string ] ) ) { return $stripScriptTags[ $string ]; } $stripScriptTags[ $string ] = $this->pregReplace( '/(.*?)<\/script>/is', '', $string ); return $stripScriptTags[ $string ]; } /** * Returns the string with incomplete HTML tags stripped. * Incomplete tags are not unopened/unclosed pairs but rather single tags that aren't properly formed. * e.g. * * @since 1.0.0 * * @param string $string The string. * @return string The modified string. */ public function stripIncompleteHtmlTags( $string ) { static $stripIncompleteHtmlTags = []; if ( isset( $stripIncompleteHtmlTags[ $string ] ) ) { return $stripIncompleteHtmlTags[ $string ]; } $stripIncompleteHtmlTags[ $string ] = $this->pregReplace( '/(^(?!<).*?(\/>)|<[^>]*?(?!\/>)$)/is', '', $string ); return $stripIncompleteHtmlTags[ $string ]; } /** * Trims HTML paragraph from the start/end of the given string. * * @since 1.0.0 * * @param string $string The string. * @return string The modified string. */ public function trimParagraphTags( $string ) { $string = preg_replace( '/^]*>/', '', $string ); $string = preg_replace( '/<\/p>/', '', $string ); return trim( $string ); } /** * Implodes an array into a WHEREIN clause useable string. * * @since 1.0.0 * * @param array $array The array. * @param bool $outerQuotes Whether outer quotes should be added. * @return string The imploded array. */ public function implodeWhereIn( $array, $outerQuotes = false ) { // Reset the keys first in case there is no 0 index. $array = array_values( $array ); if ( ! isset( $array[0] ) ) { return ''; } if ( is_numeric( $array[0] ) ) { return implode( ', ', $array ); } return $outerQuotes ? "'" . implode( "', '", $array ) . "'" : implode( "', '", $array ); } /** * Returns string after converting it to lowercase. * * @since 1.0.0 * * @param string $string The original string. * @return string The string converted to lowercase. */ public function toLowerCase( $string ) { static $lowerCased = []; if ( isset( $lowerCased[ $string ] ) ) { return $lowerCased[ $string ]; } $lowerCased[ $string ] = function_exists( 'mb_strtolower' ) ? mb_strtolower( $string, $this->getCharset() ) : strtolower( $string ); return $lowerCased[ $string ]; } /** * Convert to camelCase. * * @since 1.1.0 * * @param string $string The string to convert. * @param bool $capitalize Whether to capitalize the first letter. * @return string The converted string. */ public function toCamelCase( $string, $capitalize = false ) { $string[0] = strtolower( $string[0] ); if ( $capitalize ) { $string[0] = strtoupper( $string[0] ); } return preg_replace_callback( '/_([a-z0-9])/', function ( $value ) { return strtoupper( $value[1] ); }, $string ); } }