public static function isPrintfIsoFormat($isoFormat)
    {
        $subPattern = self::getPrintfFormatSpecifier();
        $pattern = '/(?:(?:[^%]|^)(?:%%)+(' . $subPattern . '))|(?:(?:[^%])(' . $subPattern . '))|(?:^(' . $subPattern . '))/u';

        $matches = array();
        preg_match_all($pattern, $isoFormat, $matches);

        if (count($matches[1]) + count($matches[2]) + count($matches[3]) > 0) {
            // There is at least one format specifier in the string.
            return true;
        } else {
            return false;
        }
    }
public static function isPrintfIsoFormat($isoFormat)
    {
        $subPattern = self::getPrintfFormatSpecifier();
        $pattern = '/(?:(?:[^%]|^)(?:%%)+(' . $subPattern . '))|(?:(?:[^%])(' . $subPattern . '))|(?:^(' . $subPattern . '))/u';

        $matches = array();
        preg_match_all($pattern, $isoFormat, $matches);

        if (count($matches[1]) + count($matches[2]) + count($matches[3]) > 0) {
            // There is at least one format specifier in the string.
            return true;
        } else {
            return false;
        }
    }
public static function isPrintfIsoFormat ( $ isoFormat ) { $ subPattern = self :: getPrintfFormatSpecifier ( ) ; $ pattern = '/(?:(?:[^%]|^)(?:%%)+(' . $ subPattern . '))|(?:(?:[^%])(' . $ subPattern . '))|(?:^(' . $ subPattern . '))/u' ; $ matches = array ( ) ; preg_match_all ( $ pattern , $ isoFormat , $ matches ) ; if ( count ( $ matches [ 1 ] ) + count ( $ matches [ 2 ] ) + count ( $ matches [ 3 ] ) > 0 ) { // There is at least one format specifier in the string. return true ; } else { return false ; } }
This method is not absolutely safe because of the 'volatile' nature of
the printf format. However, it can validate a lot of strings as a first
barrier for further code to be implemented.

Examples:

Format::isPrintfIsoFormat('%#x') => true
Format::isPrintfIsoFormat('%#llx') => true
Format::isPrintfIsoFormat('Octal %#x is Octal %#llx') => true
Format::isPrintfIsoFormat("%d\n") => true
Format::isPrintfIsoFormat("%3d\n") => true
Format::isPrintfIsoFormat("%03d\n") => true
Format::isPrintfIsoFormat("Characters: %c %c \n") => true
Format::isPrintfIsoFormat("Decimals: %d %ld\n") => true
Format::isPrintfIsoFormat("Preceding with blanks: %10d \n") => true
Format::isPrintfIsoFormat("Preceding with zeros: %010d \n") => true
Format::isPrintfIsoFormat("Some different radices: %d %x %o %#x %#o \n") => true
Format::isPrintfIsoFormat("floats: %4.2f %+.0e %E \n") => true
Format::isPrintfIsoFormat("Width trick: %*d \n") => true
Format::isPrintfIsoFormat("%s \n") => true
Format::isPrintfIsoFormat("%3d %06.3f\n") => true
Format::isPrintfIsoFormat("The color: %s\n") => true
Format::isPrintfIsoFormat("First number: %d\n") => true
Format::isPrintfIsoFormat("Second number: %04d\n") => true
Format::isPrintfIsoFormat("Third number: %i\n") => true
Format::isPrintfIsoFormat("Float number: %3.2f\n") => true
Format::isPrintfIsoFormat("Hexadecimal: %x\n") => true
Format::isPrintfIsoFormat("Octal: %o\n") => true
Format::isPrintfIsoFormat("Unsigned value: %u\n") => true
Format::isPrintfIsoFormat("Just print the percentage sign %%\n") => false // Do not contain valid specifier.
Format::isPrintfIsoFormat(":%s:\n") => true
Format::isPrintfIsoFormat(":%15s:\n") => true
Format::isPrintfIsoFormat(":%.10s:\n") => true
Format::isPrintfIsoFormat(":%-10s:\n") => true
Format::isPrintfIsoFormat(":%-15s:\n") => true
Format::isPrintfIsoFormat(":%.15s:\n") => true
Format::isPrintfIsoFormat(":%15.10s:\n") => true
Format::isPrintfIsoFormat(":%-15.10s:\n") => true
Format::isPrintfIsoFormat("This is an integer with padding %03d\n") => true
Format::isPrintfIsoFormat('This is an integer with padding...') => false
Format::isPrintfIsoFormat("Escape or not? %%s") => false
Format::isPrintfIsoFormat("Escape or not? %%%s") => true
Format::isPrintfIsoFormat("Escape or not? %%%%s") => false
Format::isPrintfIsoFormat("Escape or not? %%%%%s") => true
Format::isPrintfIsoFormat("%s bla %s and %%%s is %s and %%%%s") => true
Format::isPrintfIsoFormat("%%s bla %s and %%%s is %s and %%%%s") => true
Format::isPrintfIsoFormat("%%s bla %%s and %%%s is %s and %%%%s") => true
Format::isPrintfIsoFormat("%%s bla %%s and %%s is %s and %%%%s") => true
Format::isPrintfIsoFormat("%%s bla %%s and %%s is %%%%s and %%%%s") => false
Format::isPrintfIsoFormat("%s") => true
Format::isPrintfIsoFormat("%S") => false
Format::isPrintfIsoFormat("bla %S bli %s") => true

@param string $isoFormat
@return boolean
This method is not absolutely safe because of the volatile nature of the printf format . However it can validate a lot of strings as a first barrier for further code to be implemented .