Created
May 22, 2023 11:02
-
-
Save Dimasmagadan/e78b17e5dd6465f424ded15ddf7d75cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Callback function to format numbers with | |
function format_numbers_with_nbsp($content) { | |
// Regular expression pattern to match numbers | |
$pattern = '/\b(\d{1,3}(?:\d{3})*)\b/'; | |
// Replace matched numbers with formatted version | |
$formatted_content = preg_replace_callback($pattern, 'add_nbsp_to_number', $content); | |
return $formatted_content; | |
} | |
add_filter('the_content', 'format_numbers_with_nbsp'); | |
// Callback function to add to numbers | |
function add_nbsp_to_number($matches) { | |
$number = $matches[0]; | |
// Format the number by adding | |
$formatted_number = number_format($number, 0, '', ' '); | |
return $formatted_number; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment