wp_exif_frac2dec

函数
wp_exif_frac2dec ( $str )
参数
  • (string) $str Fraction string.
    Required:
返回值
  • (int|float) Returns calculated fraction or integer 0 on invalid input.
定义位置
相关方法
wp_exif_date2tswp_iframewp_verify_noncewp_text_diffwp_cache_decr
引入
2.5.0
弃用
-

wp_exif_frac2dec: 这个函数用于在WordPress中把小数转换为小数: 这个函数通常与wp_exif_date2ts一起使用,将EXIF元数据转换成可用的格式。

将一个分数字符串转换为小数点。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 WordPress.PHP.StrictComparisons.LooseComparison -- Deliberate loose comparison.
return 0;
}
return $numerator / $denominator;
}
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 WordPress.PHP.StrictComparisons.LooseComparison -- Deliberate loose comparison. return 0; } return $numerator / $denominator; }
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 WordPress.PHP.StrictComparisons.LooseComparison -- Deliberate loose comparison.
		return 0;
	}

	return $numerator / $denominator;
}

常见问题

FAQs
查看更多 >