Using PHP to format numbers

CodyBoen

Member
Hi everyone,

I am using the Custom Fields by Waindigo and I was just wondering if there is a way to format them value.

I have a classifieds section and have a spot for price and milage. I would like 30000 to become 30,000 etc. I know how to do this in PHP with
Code:
$english_format_number = number_format($number);
but I have no idea where to put it. Is there a <xen:> tag that I could use to achieve this or?

Thanks for the help!!
 
Wow. Simple enough! Thank you so much. Been scratching my head over this for a while now.

Is there a place where I can find all of the {xen:} helpers or whatever they're called??
 
Is there any way to format phone numbers by any chance?

Ex:
1234567890 to (123) 456-7890 or 123-456-7890
 
This is a very basic example of how you could do it.

PHP:
        $number = 1234567890;
        if (strlen($number) === 10)
        {
            $part1 = substr($number, 0, 3);
            $part2 = substr($number, 3, 3);
            $part3 = substr($number, 6, 4);
            $formattedNumber = "($part1) $part2-$part3";

            Zend_Debug::dump($formattedNumber);
            // returns string(14) "(123) 456-7890"
        }

You would perhaps want to make that much more robust by adding in some additional validation/error checking, but you get the idea.
 
  • Like
Reactions: KiF
This is a very basic example of how you could do it.

PHP:
        $number = 1234567890;
        if (strlen($number) === 10)
        {
            $part1 = substr($number, 0, 3);
            $part2 = substr($number, 3, 3);
            $part3 = substr($number, 6, 4);
            $formattedNumber = "($part1) $part2-$part3";

            Zend_Debug::dump($formattedNumber);
            // returns string(14) "(123) 456-7890"
        }

You would perhaps want to make that much more robust by adding in some additional validation/error checking, but you get the idea.

So basically I would just add that to library\XenForo\Template\Helper\Core.php and than call it with xen:?
 
Top Bottom