PluginProbe ʕ •ᴥ•ʔ
پارسی دیت – Parsi Date / 6.2.1
پارسی دیت – Parsi Date v6.2.1
6.2.1 6.2 6.1 5.1.6 5.1.7 5.1.8 5.1.8.2 6.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.0.0-alpha 2.1 2.1.1 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0.1 2.3.0.2 2.3.1 2.3.2 2.3.3 2.3.4 3.0.1 3.0.2 3.0.3 4.0.0 4.0.1 4.0.2 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5
wp-parsidate / inc / Helper / Number.php
wp-parsidate / inc / Helper Last commit date
Assets.php 3 weeks ago Cache.php 3 weeks ago Date.php 3 weeks ago Debug.php 3 weeks ago FeedReader.php 3 weeks ago HTML.php 3 weeks ago Helper.php 3 weeks ago JSON.php 3 weeks ago Nonce.php 3 weeks ago Notice.php 3 weeks ago Number.php 3 weeks ago NumberConverter.php 3 weeks ago Param.php 3 weeks ago Sanitizing.php 3 weeks ago Strip.php 3 weeks ago Templates.php 3 weeks ago User.php 3 weeks ago Validating.php 3 weeks ago WooCommerce.php 3 weeks ago WordPress.php 3 weeks ago
Number.php
63 lines
1 <?php
2
3 namespace WPParsidate\Helper;
4
5 class Number {
6 /**
7 * Fix numbers and convert them to Persian digits style
8 *
9 * @param string $content
10 *
11 * @return string Fixed number
12 */
13 public static function fixNumber( string $content ): string {
14 return preg_replace_callback(
15 '~<(script|style|textarea|pre|code)\b[^>]*>.*?</\1>(*SKIP)(*F)|(?:&#\d{2,4};)|(?:[0]?[a-z][\x20-\x3B=\x3F-\x7F]*)|(\d+(?:\.\d+)?)|<\s*[^>]+>~isu',
16 static function ( $matches ) {
17 return isset( $matches[2] ) ? self::toPersian( $matches[2] ) : $matches[0];
18 }, $content );
19 //return preg_replace_callback( '/(?:&#\d{2,4};)|(?:[0]?[a-z][\x20-\x3B=\x3F-\x7F]*)|(\d+[\d]*)|<\s*[^>]+>/i', 'persian_number', $content );
20 }
21
22 /**
23 * Converts English numbers to Persian numbers in post contents
24 *
25 * @param string $content Post content
26 *
27 * @return string Formatted content
28 */
29 public static function persianNumber( string $content ): string {
30 return isset( $content[1] ) ? self::toPersian( $content[1] ) : $content[0];
31 }
32
33 /**
34 * Converts English digits to Persian digits
35 *
36 * @param string $number Numbers
37 *
38 * @return string Formatted numbers
39 */
40 public static function toPersian( string $number ): string {
41 return str_replace(
42 range( 0, 9 ),
43 array( '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹' ),
44 $number
45 );
46 }
47
48 /**
49 * Converts Persian digits to English digits
50 *
51 * @param string $number Numbers
52 *
53 * @return string Formatted numbers
54 */
55 public static function toEnglish( string $number ): string {
56 return str_replace(
57 array( '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹' ),
58 range( 0, 9 ),
59 $number
60 );
61 }
62 }
63