Answers for "how to make a string a numeric value in php"

PHP
2

Convert a String to a Number in PHP

phpCopy<?php  
$variable = "53";
$integer = intval($variable);
echo "The variable $variable has converted to a number and its value is $integer.";  
echo "\n";

$variable = "25.3";
$float = floatval($variable);
echo "The variable $variable has converted to a number and its value is $float.";  
?>
Posted by: Guest on April-23-2021
0

get numbers from string php

phpCopy<?php 
$string = 'Sarah has 4 dolls and 6 bunnies.';
preg_match_all('!\d+!', $string, $matches);
print_r($matches); 
?>
Posted by: Guest on April-23-2021

Code answers related to "how to make a string a numeric value in php"

Browse Popular Code Answers by Language