• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

regular expressions

$var = string101;
$var = string1012;
$var = string10123;

hi how can i use regular expression to retrieve only the numbers from this variable in php
0
woleraymond
Asked:
woleraymond
1 Solution
 
RobOwner (Aidellio)Commented:
use preg_match

<?php
$var1 = string101;
$var2 = string1012;
$var3 = string10123;

$pattern = '/[0-9]+/';
preg_match($pattern, $var1, $matches);

$num1 = $matches[0];

?>

this would have $num1 = 101;

you could repeat for the others
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now