How to Extract Numbers from String in PHP
- Tech Area
- Last updated on: January 8, 2026
In this tutorial, We will see how to extract the numbers from the string using the PHP inbuilt function. We are using filter_var() function to filters a variable with the FILTER_SANITIZE_NUMBER_INT. This function is used to both validate and sanitize the data.
Solution
<?php
$string = 'Welcome 2 the Tech Area';
$number = filter_var($string, FILTER_SANITIZE_NUMBER_INT);
echo $number;
?>
Output
2
Subscribe us via Email
Join 20,000+ subscriber
PHP Projects
Employee Attendance & Leave Management System project in PHP & MySQL
Last Updated: January 24, 2026
Matrimonial Portal Project in PHP & MySQL
Last Updated: December 22, 2025
Event Management System Project in PHP & MySQL
Last Updated: December 6, 2025
Online Shopping System Project in PHP MySQL
Last Updated: November 26, 2025
Student record system project in PHP and MySQL
Last Updated: July 3, 2024
Food ordering system project in PHP and MySQL
Last Updated: June 27, 2024
Tourism management system project in PHP and MySQL
Last Updated: June 24, 2024
Restaurant table booking system project in PHP and MySQL
Last Updated: February 22, 2024
Hostel management system project in PHP and MySQL
Last Updated: February 14, 2024
Online Pizza Delivery project in PHP
Last Updated: February 4, 2024
Parking Management System project in PHP
Last Updated: November 5, 2023
Employee Attendance Management System project in PHP MySQL
Last Updated: October 3, 2023
Visitors Management System project in PHP
Last Updated: August 28, 2023
Library Management System project in PHP and MySQL Updated 2026
Last Updated: May 29, 2023
Expense Management System project in PHP and MySQL
Last Updated: May 22, 2023
Hospital Management System project in PHP and MySQL
Last Updated: May 5, 2023
Online quiz with e-certificate in PHP CodeIgniter with MySQL
Last Updated: April 29, 2023
SNIPE – IT Asset management system v6.1.0
Last Updated: April 21, 2023
Online Quiz System project in PHP CodeIgniter with MySQL
Last Updated: February 8, 2023
Employee Management System project in PHP
Last Updated: January 21, 2023
