Is it possible using PHP to strip everything from a string after and including the first ‘non’ letter?
E.g.
Blue Bayou (1954) becomes Blue Bayou
Hello World: 1234 becomes Hello World
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That’s doable with
preg_replaceas follows:The
/[^\w\s].+$/is the small regex micro-program. It looks for the first character that is neither a letter\wor a space\sand matches anything else.*after that.And
""is the empty string which replaces the matched parts. Note that a space afterBayouwill be kept in example 1. (Wanted to keep the example short. But see the comment! ha)