chapter5PHPTUT-nicephotog

download chapter5PHPTUT-nicephotog

of 1

Transcript of chapter5PHPTUT-nicephotog

  • 8/9/2019 chapter5PHPTUT-nicephotog

    1/1

    Chapter 6 PHP File I/O and String Regular Expression engine

    (Chapter 5) PHP Arithmetic operators and predefined functions (and String functions)

    Arithmetic constants and Properties

    One of the major actions of computing is mathematics. Maths is difficult and accuracy is of real worldvalue in anything now whether it be a simple add and subtract site shopping cart monetary total or amore valid problem of unit conversion of some type of measurement of bickies whether large quantitiesof money in an exchange rate ration of standard economic foreign units.

    So nothing now changes for this programming language(PHP) as any of its predecessors e.g. PERL C/C++ Shell.All of these have three R's of computing maths,R predefined functions for trigonometry, R Coefficient constants,R standard fractional computer architecture typing e.g. Integer , Float.In computing a constant is variable to which a value cannot be re-assigned but either only initialised or as

    below, pre-set by the language script engine by both semantic syntax and reference name.The variable M_PI below is not changeable and is the value of PI, the coefficient for circle geometry.M_PI 3.14159265358979323846 Pianotheris the Euler constant that comes from fractional maths of numerator/denominator system.M_EULER 0.57721566490153286061and again as would be there are logarithms.

    Arithmetic operators

    Arithmetic operators are along the same again for most languagesthe star * is the multiplication operator

    $nine=3*3;the forward slash / operator is the division operator$four=12/3; the plus sign + operator is for addition$ten=5+5;the minus sign(hyphen) - is the subtraction operator$seven=10-3;and the modulus % sign(percent sign) is the remainder of a division$zero=12/4;This now comes to operator precedence being of importance and beingdifficult to discern some errors in maths until identified e.g.4+3*7/7 if you were to do this from left to right as you found thenumbers you would get 7 but if you do it by precedence using parenthesisyou would get 7 a completely different way 4+(3*7)/7 because of them

    being grouping operators , and a completely different one algebraicallyby precedence and associatively with no parenthesis by the PHP.This is better explained by the PHP Manual's example but that's effectively it.As i told you before, operator precedence has some part in maths and toachieve better synchronisis of equation sequences the grouping operator

    parenthesis can be used to cause internal declarations of code to bemanaged as a single entity and not simply inline or by plain declarationprecedence.

    PHP Engine, precence , algebraic evaluation logic examples

    Pre-Defined Math functions in PHP

    Standard expectable programming language trigonometric functions exist in PHP.One of the less usual is rand() used to generate random numbers.rand takes aminimum and a maximum number for its arguments and outputs thatever comes of it.hypot() returns the length of the hypotenuse.ceil() for rounding up.

    String functions/operations

    At present and now is the final time/moment gone to leave this to, i will explain some basic standard string handling functions.These are extremely important because much of anything www and web servers have and alike to the http and ftp networking protocolis text whether data or commands. Earlier in this tutorial you found text and maths are unavoidable at some point because of howcomputers operate and how that operation needs to be interfaced to most possibly and at some point a human user. Strings are madeof individual characters and without regard to byte size of singular or pairs to make a string it has a length. consider if as youlearned before that windows has the new line 4 byte character and we put with it to make a reference to a string one more character,that would make 3 characters and a length of three would it?. Answer NO.Only two. Two, because new line is for purpose onecharacter but better as one symbolic representation,meaning it only represents a new line and nothing else. In most scriptinglanguages it is not the operational method of data typing to be extremely definitive of the data unlike C/C++ because a string whileit is an array of characters does not actually change its data type to a character except during exceptive and deliberate programmercontrolled chosen situations and is never actually a character data type.One single character is always a string not a char.Whenhandling strings it is often required to know the length strlen() of it because they are often operated on in a for() loop fromstart to finnish,moreover they are often required to have two(a pair) not one set of positions in the string being related and workedupon in the one iteration sequence of the loop(a start and an end of another relevant string). The position of strings absolute start

    is always zero and it end is always its length minus -1(one).These type of functions are always found when stringhandling. strlen() , substr() ltrim() rtrim().

    http://nicephot.xlphp.net/chapter6PHPTUT.htmlhttp://au3.php.net/manual/en/language.operators.php#language.operators.precedencehttp://au3.php.net/manual/en/language.operators.php#language.operators.precedencehttp://nicephot.xlphp.net/chapter6PHPTUT.html