wpseek.com
Un motore di ricerca WordPress per sviluppatori e autori di temi



wp_exif_frac2dec › WordPress Function

Da2.5.0
Deprecaton/a
wp_exif_frac2dec ( $str )
Parametri:
  • (string) $str Fraction string.
    Richiesto:
Ritorna:
  • (int|float) Returns calculated fraction or integer 0 on invalid input.
Definito a:
Codex:

Converts a fraction string to a decimal.



Sorgenti

function wp_exif_frac2dec( $str ) {
	if ( ! is_scalar( $str ) || is_bool( $str ) ) {
		return 0;
	}

	if ( ! is_string( $str ) ) {
		return $str; // This can only be an integer or float, so this is fine.
	}

	// Fractions passed as a string must contain a single `/`.
	if ( substr_count( $str, '/' ) !== 1 ) {
		if ( is_numeric( $str ) ) {
			return (float) $str;
		}

		return 0;
	}

	list( $numerator, $denominator ) = explode( '/', $str );

	// Both the numerator and the denominator must be numbers.
	if ( ! is_numeric( $numerator ) || ! is_numeric( $denominator ) ) {
		return 0;
	}

	// The denominator must not be zero.
	if ( 0 == $denominator ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual -- Deliberate loose comparison.
		return 0;
	}

	return $numerator / $denominator;
}