Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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
011569875
041568956
011
substr()
if (Substr($MyString,0,3)=="011") { echo $MyString;}
echo substr($number,0,3) == '011' ? $number : '';
As suggested by @Mark, you can use substr as follows:
substr
$string = substr($longstring,0,3); if($string == '011'){ echo $longstring; }
Hope this helps. Cheers
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
substr()?substr()for this purpose?if (Substr($MyString,0,3)=="011") { echo $MyString;}echo substr($number,0,3) == '011' ? $number : '';assuming your values are really strings