Byt Wiki

Format Functions Documentation

This file contains functions related to formatting, including currency formatting, string manipulation, and HTML sanitization.

formatCurrency

Formats a number as currency.

Usage

$formatted = formatCurrency(1234.56, '$');
echo $formatted; // Output: $1,234.56

Parameters

Returns

formatDate

Formats a date to a specified format.

Usage

$formattedDate = formatDate('2024-07-30 13:49:26', 'F j, Y, g:i a');
echo $formattedDate; // Output: July 30, 2024, 1:49 pm

Parameters

Returns

formatSizeUnits

Formats a number of bytes into a human-readable format.

Usage

$size = formatSizeUnits(1024);
echo $size; // Output: 1 KB

Parameters

Returns

formatPhoneNumber

Formats a phone number into a standard format.

Usage

$phoneNumber = formatPhoneNumber('1234567890');
echo $phoneNumber; // Output: (123) 456-7890

Parameters

Returns

sanitizeFilename

Converts a string to a safe filename.

Usage

$safeFilename = sanitizeFilename('example image.png');
echo $safeFilename; // Output: example_image.png

Parameters

Returns

escapeHtml

Escapes special characters to HTML entities.

Usage

$html = escapeHtml('<div>"Hello"</div>');
echo $html; // Output: &lt;div&gt;&quot;Hello&quot;&lt;/div&gt;

Parameters

Returns

stripTagsExcept

Strips HTML tags except specified ones.

Usage

$cleanHtml = stripTagsExcept('<p>Hello <b>World</b></p>', ['<b>']);
echo $cleanHtml; // Output: Hello <b>World</b>

Parameters

ΒΆReturns