How to convert characters to numbers in php

王林
Release: 2023-03-02 19:32:02
Original
2968 people have browsed it

The way to convert characters into numbers in php is: you can use the intval() function. This function returns the integer value of the variable by using the specified base conversion. The specific usage method is: [echo intval('42');], in which the integer 42 will be output.

How to convert characters to numbers in php

Related function introduction:

intval() function is used to obtain the integer value of a variable.

(Recommended tutorial:php tutorial)

intval() function returns the integer value of variable var by using the specified base conversion (default is decimal). intval() cannot be used with object, otherwise an E_NOTICE error will be generated and 1 will be returned.

Function syntax:

int intval ( mixed $var [, int $base = 10 ] )
Copy after login

Parameter description:

  • $var: the quantity value to be converted into integer;

  • $base: The base used for conversion. If base is 0, the base used is determined by detecting the format of var;

  • If the string includes the prefix of "0x" (or "0X"), use hexadecimal (hex);

  • If the string starts with "0", use octal (octal);

Return value:

Returns the integer value of var on success, and returns 0 on failure. An empty array returns 0, a non-empty array returns 1.

Code:

How to convert characters to numbers in php

The above is the detailed content of How to convert characters to numbers in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!