- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert a string into number in PHP?
To convert a string into a number, the code is as follows−
Example
<?php $str = "150"; $num = (int)$str; echo "Number (Converted from String) = $num"; ?>
Output
This will produce the following output−
Number (Converted from String) = 150
Example
Let us now see another example−
<?php $str = "100.56"; echo "String = $str"; $num = floatval($str); echo "
Number (Converted from String) = $num"; ?>
Output
This will produce the following output−
String = 100.56 Number (Converted from String) = 100.56
Advertisements