Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression matched first 3 character of string in PHP

Tags:

regex

php

I am looking for a pattern regular expression that is matching of first 3 character of string.
For example , I have two number like this: 011569875 and 041568956
If I found first 3 character 011 ,then I will print 011569875

like image 469
Alien Avatar asked Oct 30 '22 17:10

Alien


1 Answers

As suggested by @Mark, you can use substr as follows:

$string = substr($longstring,0,3);
if($string == '011'){
   echo $longstring;
}

Hope this helps. Cheers

like image 158
Tarunn Avatar answered Nov 02 '22 10:11

Tarunn