PHP Classes
elePHPant
Icontem

File: README.txt

Recommend this page to a friend!
  Classes of Alex F. Bustos  >  SI Prefix Converter  >  README.txt  >  Download  
File: README.txt
Role: Documentation
Content type: text/plain
Description: Brief of how to use the class
Class: SI Prefix Converter
Convert a number to a string appending a prefix
Author: By
Last change: upload temp files
Date: 3 years ago
Size: 2,928 bytes
 

Contents

Class file image Download
File: readme.txt
Created by: Alex Bustos - @alexfbp

At first, Thanks for downloading and testing it.

This file is a little resume and explanation on how to use
this class. For specific details, see the class and demo files.

=======================================
INITIALIZATION STEPS

1. Include, instantiate and (opt) set the numeric and list limitations
	include('settings.inc.php'); //Maybe you want to change some default values
	include('sci.class.php');
	$sci=new sci('LOP'[,- more options-]); //See the __construct() function for details.
If the first argument of the construct is a variable, you must be sure that this variable
is sanitized, has not forbidden expressions such as "..", "/", etc...
The 'LOP' (List Of Prefixes) are the DESIRED list, not the used list which
are generated internally through a call to the start() function (step 4)

2. (opt) Set the numeric out format. By decimal places or significant digits
	$sci->set_round_params();

3. (opt) Insert Additive Rules
	$sci->set_single_rule();
	$sci->set_scale_rule();
	$sci->set_all_rule();

4.	$sci->start(); //the object.
Else, the main functions will return the unmodified value

=======================================
MAIN FUNCTIONS:

mixed get_prefixed(mixed $value,bool $array=false):
	Returns a string like $number.$join.$prefix. based on a previously choosen
	List of Prefixes.
	
	The $join value was previously defined when instantiating the object.

	Or, if you want to format the prefix as you want, you can set $array=true,
	and the function will return an array($number,$prefix);

mixed get_number(string $string, bool $entities=true, $flags=ENT_COMPAT)
	If you want to do the inverse process, here comes that function.
	May return a float or a int.
	Prior to use this function, you should configure the charset.

=======================================
CONFIGURATION FUNCTIONS:
sci::valid_list($LOP) - Basic validation if a List of Prefixes $LOP are in the allowed format.
set_round_params() - Rounding Configuration. See the class and then http://www.php.net/manual/en/function.round.php
set_charset($charset) - Valid Charset. See the $encoding arg of https://php.net/manual/es/function.htmlentities.php 

=======================================
RULE FUNCTIONS: Add to the ALLOWED list, from the DESIRED list
(and if the exponent are valid in the specified range):

	set_single_rule($exponent); //a prefix of the same exponent
	set_scale_rule($scale); //each prefix multiple of $scale
Omitting the limits, ej:
with 3, allowed exps will have too {...,-9,-6,-3,0,3,6,9,...}
with 2, allowed exps will have too {...,-6,-4,-2,0,2,4,6,...}
and so...
	
	set_all_rule(); //All of the prefixes

If needed, to understand the differences between the allowed and desired lists,
var_dump an sci object, before and after to the call to start():

$sci=new sci();
var_dump($sci);
... //Maybe you wish to add some rules
$sci->start();
var_dump($sci);