jamesxg1 Posted December 14, 2010 Share Posted December 14, 2010 Hiya peeps, I am using preg_match to validate URLS; preg_match("/(((https?|ftp|gopher):\/\/|(mailto|file|news)[^' <>\"]+|(www|web|w3).[-a-z0-9.]+)[^' .,;<>\":]/i", $this->_searchString) I works great, the only issue I have is I am using it in an if statment, and what I need to do is something like this. if(preg_match("/(((https?|ftp|gopher):\/\/|(mailto|file|news)[^' <>\"]+|(www|web|w3).[-a-z0-9.]+)[^' .,;<>\":]/i", $this->_searchString)) { CHECK IF $this->_searchString has http:// at the start of it or if it has a / at the end and remove them if it does. I need $this->_searchString to end up with only www.SITE.co.uk before I can input it into the relevant function. } else { } Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/221638-if-an-input-has-specific-characters-strip-them/ Share on other sites More sharing options...
MMDE Posted December 14, 2010 Share Posted December 14, 2010 from what the thread title "wants", look into preg_replace(); Link to comment https://forums.phpfreaks.com/topic/221638-if-an-input-has-specific-characters-strip-them/#findComment-1147219 Share on other sites More sharing options...
AbraCadaver Posted December 14, 2010 Share Posted December 14, 2010 Maybe use functions that are built for this if(filter_var($this->_searchString, FILTER_VALIDATE_URL)) { $this->_searchString = parse_url($this->_searchString, PHP_URL_HOST); } Link to comment https://forums.phpfreaks.com/topic/221638-if-an-input-has-specific-characters-strip-them/#findComment-1147220 Share on other sites More sharing options...
jamesxg1 Posted December 14, 2010 Author Share Posted December 14, 2010 Thanks mate, worked a charm . Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/221638-if-an-input-has-specific-characters-strip-them/#findComment-1147225 Share on other sites More sharing options...
AbraCadaver Posted December 14, 2010 Share Posted December 14, 2010 Thanks mate, worked a charm . Many thanks, James. Just noticed your sig. I love it! Link to comment https://forums.phpfreaks.com/topic/221638-if-an-input-has-specific-characters-strip-them/#findComment-1147250 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.