Description: Spintax Function
Submitted on November 14, 2017 at 03:50 PM

New Paste 1 (PHP)

function my_spintax( $string ) {
	$data = preg_match_all( "/(?=\{).*?(?=\})./", $string, $match );
	
	if ( !empty( $match ) ) {
		foreach ( $match as $key => $value ) {
			if ( !empty( $value ) ) {
				foreach ( $value as $values ) {
					$v = explode( "|", $values );
					$i = array_rand( $v );
					$string = str_replace( $values, str_replace( array( "{", "}" ), "", $v[ $i ] ), $string );
				}
			}
		}
	}
	return $string;
}