Converter



( ZN >= 1.0.0 )

The class that hosts the methods that convert in the encodings. It was created to do various type conversions as well as type conversions. There are a number of ways in which we think you will work with more.

 

 

# Methods


String byte ( Int $ bytes , Int $ precision = 1 , Bool $ unit = true )
float toBytes ( Float $ value )
String money ( Int $ money = 0 , String $ type = NULL )
float moneyToNumber ( String $ money )
float time ( Int $ count , String $ type = 'second' , String $ output = 'day' )
String word ( String $ string , Mixed $ badWords = NULL , $ changeChar = '[badwords]' )
String anchor ( String $ data , String $ type = 'short' , Array $ attributes = NULL )
String char ( String $ string , String $ type = 'char' , String $ changeType = 'html' )
String accent ( String $ str )
String urlWord ( String $ str , String $ splitWord = '-' )
String slug ( string $ str , boolean $ protectextensio's = false )
String stringCase ( String $ str , String $ type = 'lower' , String $ encoding = 'utf-8' )
Array arrayCase ( Array $ array , String $ type = 'lower' , String $ keyval = 'all' )
String charset ( String $ str , String $ fromCharset , String $ toCharset = 'utf-8' )
String highLight ( String $ str , Array $ settings = []
String toString ( Mixed $ var )
String toConstant ( Mixed $ var , String $ prefix , String $ suffix )

 

 

# Byte ( ZN >= 4.0.1-EIP )


byteConverts the amount of bytes entered into interest .

Parameters

Int $ bytes Number of bytes in the digital type.
Int $ precision = 1 How many characters will be in decimal part.
Bool $ unit = true Is your name displayed?
return String

uses

echo Converter::byte(1000000, 2);
echo Converter::byte(1000000, 1, false);
976.56 KB
976.6

 

 

# ToBytes ( ZN FE 5.5.9 )


Using byte () unlike the method of 20MB , 5GB asstringconverts the values ​​to bytes .

Parameters

String $ Value The string to translate.
return float

uses

echo Converter::toBytes('1KB');
1024

 

 

# Money ( ZN> = 4.0.1-EIP )


Turns the entered number to the paratouch.

Parameters

Int $ money The numeric value to be converted to currency format.
String $ type = NULL Currency. ( ZN> = 5.3.9 ) The unit is added to the end. To get it to the beginning of the parameter value! sign is added.
return String

uses

echo Converter::money(1000000, '£');
echo Converter::money(1000000, '$', false);
£ 1,000,000.00 £
1,000,000 

Starting the Param Unit ( ZN> = 5.3.9 )

For this, the sign of the 2nd parameter is added.ünlem(!)

echo Converter::money(1000000, '!£');
echo Converter::money(1000000, '!$', false);
£ 1,000,000,000
$ 1,000,000 

 

 

# MoneyToNumber ( ZN> = 5.2.0 )


Converts the currency format converted with the Converter :: money () method to a float type number.

Parameters

String $ money Currency formatted data to be converted to numeric format.
return float

uses

echo Converter::moneyToNumber('1.000.000,00');
1000000

 

 

# Time ( ZN >= 4.0.1-EIP )


Turns the entered number to the zamantouch.

Parameters

Int $ count Number.
String $ inputType = 'second' The type of time entered.
String $ outputType = 'day' Converted time type.
return float

uses

\Output::writeLine( Converter::time(120, 'second', 'minute') );
\Output::writeLine( Converter::time(120, 'day', 'month') );
\Output::writeLine( Converter::time(12, 'month', 'year') );
2
4

 

 

# Word ( ZN> = 4.0.1-EIP )


The conversion of unwanted characters is provided.

Parameters

String $ word The data to be converted.
Mixed $ badWords = NULL Unwanted words.
Mixed $ changeCar = '[badwords]' String or array to replace undesired characters.
return String

uses

\Output::writeLine( Converter::word('Hi, ? Guys', '?') );
\Output::writeLine( Converter::word('Hi, ? Guys', [',', '?']) );
\Output::writeLine( Converter::word('Hi, ? Guys', [',', '?'], ['x', 'y']) ); 
Hi, [badwords] Guys
Hi [badwords] [badwords] Guys
Hix y Guys 

 

 

# Anchor ( ZN >= 4.0.1-EIP )


Link string of HTML < A > is used to convert the label.

Parameters

String $ data Data to be converted into a bridge.
String $ type = 'short' View the length of the link.
short Used to name the look of the link.
longan The link view is the same as the href value.
Array $ attributes = [] Attribute value pair.
return String

uses

\Output::writeLine( Converter::anchor('https://www.znframework.com', 'short', ['id' => 'convert']) );
\Output::writeLine( Converter::anchor('https://www.znframework.com', 'long', ['id' => 'convert']) );
< A href = "= https://www.znframework.co I" was to "convert"> znframework < / a>
< a href = "https://www.znframework.co I" id = "convert"> https: / /www.znframework.com < / a>

 

 

# Char ( ZN >= 4.0.1-EIP )


Used to convert characters to html , decimal, or hexdecimal character format.

Parameters

String $ data Characters to be translated.
String $ inputType = 'char' Input type.
String $ outputType = 'html' Output type.
return String

Convertible Types

char Normal character.
html HTML numeric character format.
dec Decimal character format.
hex Hexdecimal character format.

uses

\Output::writeLine( Converter::char('Example Data') );
\Output::writeLine( Converter::char('Example Data', 'char', 'dec') );
\Output::writeLine( Converter::char('Example Data', 'char', 'hex') );
& # 69; & # 120; & # 97; & # 109; & # 112; & # 108; & # 101; & # 68; & # 97; & # 116; & # 97;
69 120 97 109 112 108 101 68 97 116 97
45 78 61 6D 70 6C 65 44 61 74 61 

 

 

# Accent ( ZN >= 4.0.1-EIP )


Different language accent characters, which consist of differences in standards translates into character format. 

Parameters

String $ data The string to be translated.
return String

uses

echo Converter::accent('Åççeňt');
Accent

Extending the Accent Character Set

You can expand the accentChars sequence in the following file to add your own character set except for predefined cycles in the system .

File: Settings / Expressions.php

 

 

# UrlWord ( ZN> = 4.0.1-EIP )


Converts sentence structures into sentence structure suitable for URL structure.

Parameters

String $ data The string to be translated.
String $ split = '-' Combining expression.
return String

uses

\Output::writeLine( Converter::urlWord('Welcome to ZN') );
\Output::writeLine( Converter::urlWord('Welcome to ZN', '/') );
welcome-to-zn
welcome / to / zn 

 

 

# Slug ( ZN >= 4.4.9 )


The urlWord () method can also be used for this. However, this method urlword () separating the portion of the method 2 can not select the separator character. That is, it inserts a - (hyphen) symbol between words. At the same time, this method ignores all special characters, unlike the urlWord () method.

Parameters

String $ data The string to be translated.
Bool $ protectExtension = false Are extension preserved? Only the name part is used in the file names.
return String

uses

\Output::writeLine( Converter::slug('Welcome to ZN') );
welcome-to-zn

Extension Protection ( ZN >= 5.4.25 )

If the data to be slug contains a file name and only the file name needs to be translated, the second parameter is used.

\Output::writeLine( Converter::slug('Example File.php', true) );
example-file.php

As we have seen above, translation has not been changed, only the name extension has been split.

 

 

# StringCase ( ZN >= 4.0.1-EIP )


Large textual expressions are used to convert small, large, or just the first letter to uppercase.

Parameters

String $ data The string to be translated.
String $ type = 'lower' Which type to convert is specified.
lower Converts the whole string to lower case.
upper Converts whole string to upper case.
title The whole string converts the first letter of each word to the capitalized rest.
return String

uses

\Output::writeLine( Converter::stringCase('Welcome to ZN') );
\Output::writeLine( Converter::stringCase('Welcome to ZN', 'upper') );
\Output::writeLine( Converter::stringCase('Welcome to ZN', 'title') );
welcome to zn
WELCOME TO ZN
Welcome To Zn 

 

 

# ArrayCase ( ZN> = 4.0.1-EIP )


Used to convert uppercase and lowercase letters in array elements. This can be done either on array keys or on array elements, if you want.

Parameters

Array $ data Sequence.
String $ type = 'lower' Kind.
lower Convert elements to lowercase.
upper Convert elements to upper case.
title Convert only the first letter of the elements to the lower case lower case.
String $ keyval = 'all' Affected by conversion.
all Both keys and values ​​are affected by the cycle.
the key Only the keys are affected by the cycle.
value Only values ​​are affected by the cycle.
return Array

uses

output( Converter::arrayCase(['Hello' => 'Guys'], 'upper', 'all') );
output( Converter::arrayCase(['Hello' => 'Guys'], 'upper', 'value') );
output( Converter::arrayCase(['Hello' => 'Guys'], 'title', 'key') ); 
HELLO => string 'Guys' (length = 6 )
Hello => string 'Guys' (length = 6 )
Hello => string 'Guys' (length = 6 )

 

 

# Charset ( ZN >= 4.0.1-EIP )


The string is used to change the character set.

Parameters

String $ data Data.
String $ fromcharset From which character set.
String $ toCharset = 'utf-8' Which character set.
return String

uses

echo Converter::charset('Åççeňt', 'UTF-8', 'JIS');
テ? ナ テ ァ テ ァ e? T 

 

 

# HighLight ( ZN >= 4.0.1-EIP )


Convert PHP string to color codes.

Parameters

String $ data The data will be converted to sabite.
Array $ settings Settings.
php: family PHP font type.
php: you PHP font size.
php: style PHP style usage.
html: family HTML font type.
HTML: you HTML font size.
html: color HTML font color.
html: style Use of HTML style.
comment: color Description line color.
comment: style Description line style usage.
default: color The default color.
default: style Default style.
keyword: color The color of the keywords.
keyword: style The style of the keywords.
string: color String color.
string: style Use of string style.
background Background style use.
tags Using PHP tags style
return String

uses

echo Converter::highLight('<?php echo $variable;');
< ? php echo $ variable

 

 

# ToString ( ZN> = 4.0.1-EIP )


Converts the data to string.

Parameters

Mixed $ data The data to be converted to string.
return String

uses

echo Converter::toString(['Z', 'N']);
ZN

 

 

# To C onstant ( ZN >= 4.0.1-EIP )


Transforms the constant into constant.

Parameters

Mixed $ data The data will be converted to sabite.
String $ prefix Prefix.
String $ suffix The last appendix.
return Mixed

uses

\Output::writeLine( Converter::toConstant('PHP_VERSION') );
\Output::writeLine( Converter::toConstant('VERSION', 'PHP_') );
\Output::writeLine( Converter::toConstant('VER', 'PHP_', 'SION') ); 
7.0.8
7.0.8
7.0.8