grissom Posted January 19, 2012 Share Posted January 19, 2012 Hi folks, I'd be very grateful if you could help as regex is not my forte. I'm looking for something to strip any punctuation characters from the start of a string but retain any punctuation characters thereafter. For example &!%^:Hello World : it's a nice day ! would return Hello World : it's a nice day ! Many thanks ! Link to comment https://forums.phpfreaks.com/topic/255364-strip-non-alphanumeric-from-start-of-string/ Share on other sites More sharing options...
JAY6390 Posted January 19, 2012 Share Posted January 19, 2012 $output = preg_replace('~^[^\da-z]+~i', '', $input); That will replace any characters at the start of a string up until the first letter or number only Link to comment https://forums.phpfreaks.com/topic/255364-strip-non-alphanumeric-from-start-of-string/#findComment-1309259 Share on other sites More sharing options...
grissom Posted January 19, 2012 Author Share Posted January 19, 2012 THANKS JAY That worked like a charm ! I can really admire someone who can sort out regex, whenever I try it's like doing a Rubik's cube in the dark. Thanks again. Link to comment https://forums.phpfreaks.com/topic/255364-strip-non-alphanumeric-from-start-of-string/#findComment-1309265 Share on other sites More sharing options...
JAY6390 Posted January 19, 2012 Share Posted January 19, 2012 haha I know that feeling Link to comment https://forums.phpfreaks.com/topic/255364-strip-non-alphanumeric-from-start-of-string/#findComment-1309310 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.