simonp Posted June 2, 2010 Share Posted June 2, 2010 Hi, I'm looking to use regex to ensure a field begins with http:// Can anyone tell me how I can do that? Thanks Simon Link to comment https://forums.phpfreaks.com/topic/203626-regex-help/ Share on other sites More sharing options...
Adam Posted June 2, 2010 Share Posted June 2, 2010 You don't need regexp for that, you can just use substr: if (substr($str, 0, 7) == 'http://') { Link to comment https://forums.phpfreaks.com/topic/203626-regex-help/#findComment-1066597 Share on other sites More sharing options...
salathe Posted June 2, 2010 Share Posted June 2, 2010 You don't need substr for that, you can use strpos: if (strpos($str, 'http://') === 0) { Link to comment https://forums.phpfreaks.com/topic/203626-regex-help/#findComment-1066598 Share on other sites More sharing options...
Adam Posted June 2, 2010 Share Posted June 2, 2010 Touché! Link to comment https://forums.phpfreaks.com/topic/203626-regex-help/#findComment-1066600 Share on other sites More sharing options...
simonp Posted June 2, 2010 Author Share Posted June 2, 2010 ok you two - that's scary! Unforuntately, it's being checked by a third party piece of software that I need to put in a regexp Any ideas? Cheers Link to comment https://forums.phpfreaks.com/topic/203626-regex-help/#findComment-1066601 Share on other sites More sharing options...
Adam Posted June 2, 2010 Share Posted June 2, 2010 Yar: if (preg_match('#^http://#', $str)) { Using "#" as the delimiter or it just looks ridiculous. Link to comment https://forums.phpfreaks.com/topic/203626-regex-help/#findComment-1066604 Share on other sites More sharing options...
simonp Posted June 2, 2010 Author Share Posted June 2, 2010 Thanks MrAdam - simple! Link to comment https://forums.phpfreaks.com/topic/203626-regex-help/#findComment-1066609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.