Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

TutsPlus.com:
PHP Integers, Floats, and Number Strings
Nov 12, 2018 @ 18:11:39

On the TutsPlus.com site they've continued their series of posts introducing you to some of the basic functionality included with the PHP language. In this latest tutorial they focus on integers, floats, and number strings and how to determine which you're using.

Working with numbers in PHP seems to be a trivial concept, but it can be quite confusing. It looks easy at first because PHP provides automatic type conversion. For example, you can assign an integer value to a variable, and the type of that variable will be an integer. On the next line, you can assign a string to the same variable, and the type will change to a string. Unfortunately, this automatic conversion can sometimes break your code.

There are a lot of types for numeric values as well. In this tutorial, you'll learn about integers and floats in PHP, as well as the functions which can be used to determine the type of numbers that we are dealing with and convert between them. You'll also learn how to convert integers and floats to and from numerical strings.

The post starts by giving a summary of each of the types - integers and floats - along with the concepts of infinity and NaN. It then covers the use of "numerical strings" in PHP and the automatic type switching that can happen when using them with actual number values. The post wraps up with examples of how to cast values from strings to integers (and back) along with some final thoughts.

tagged: tutorial integer float numberstring number introduction beginnner

Link: https://code.tutsplus.com/tutorials/php-integers-floats-and-number-strings--cms-32048

DevShed:
Validating Boolean Values and Float Numbers with Filters in PHP 5
Aug 06, 2009 @ 12:51:05

Continuing their "validation in PHP" series, DevShed has posted this new tutorial looking at the validation of boolean values and float numbers in PHP5 applications (with the filter extension).

As you learned in previous parts of the series, the filter extension permits you to validate elements of a given array very easily as well. Therefore, in this fourth chapter I'm going to explain how to check for Boolean values in arrays, as well as how to validate float numbers using another handy filter.

the examples are pretty simple, running a filter_var on the values to check if it's a boolean and to require that the set of values comes in as an array.

tagged: tutorial boolean filter extension float

Link:

Danne Lundqvist's Blog:
Zend Framework and locales
Apr 01, 2009 @ 18:44:18

In a new post to his blog Danne Lundqvist take a look at using locales in the Zend Framework and a "gotcha" that made him look deeper.

Last night I spent a couple of hours with Zend Framework and especially Zend_Form. I discovered, and now also reported as ZF-6175, a bug in Zend_Validate_Float when using a locale with a decimal point other than ".". There are unit tests but none that test Zend_Validate_Float under a different locale.

He points out that floats are locale-aware in PHP itself (code examples) and how the current Zend_Validate float package handled it. He has already proposed a fix for the problem and, until its changed in the framework, has provided the simplified code you can use.

tagged: zendframework locales float number zendvalidatefloat

Link:

Paul Jones' Blog:
Sanitation with PHP filter_var()
Jan 17, 2007 @ 21:22:00

In working on a new filter for his Solar framework, Paul Jones discovered that the "float" sanitizer in the new filter extension (PHP 5.2+) doesn't quite work as expected.

I found a problem with the "float" sanitizing function in the 5.2.0 release, and thought others might want to be aware of it. In short, if you allow decimal places, the sanitizer allows any number of decimal points, not just one, and it returns an un-sanitary float.

He includes the text of the bug he submitted as an example of how the error might happen and, despite it being marked bogus, Paul still holds that things are still not working like they should.

You can also check out Pierre-Alain Joye's response to this over on his blog.

tagged: filter extension sanitatinon filtervar float solar framework filter extension sanitatinon filtervar float solar framework

Link:

Paul Jones' Blog:
Sanitation with PHP filter_var()
Jan 17, 2007 @ 21:22:00

In working on a new filter for his Solar framework, Paul Jones discovered that the "float" sanitizer in the new filter extension (PHP 5.2+) doesn't quite work as expected.

I found a problem with the "float" sanitizing function in the 5.2.0 release, and thought others might want to be aware of it. In short, if you allow decimal places, the sanitizer allows any number of decimal points, not just one, and it returns an un-sanitary float.

He includes the text of the bug he submitted as an example of how the error might happen and, despite it being marked bogus, Paul still holds that things are still not working like they should.

You can also check out Pierre-Alain Joye's response to this over on his blog.

tagged: filter extension sanitatinon filtervar float solar framework filter extension sanitatinon filtervar float solar framework

Link:


Trending Topics: