Vivid Lust Posted February 6, 2009 Share Posted February 6, 2009 Hi all, Is there any way in which with PHP, i can check to see if http:// is present at the start of a string? Thanks all. Quote Link to comment https://forums.phpfreaks.com/topic/144111-check-that-string-has-http-at-the-start/ Share on other sites More sharing options...
premiso Posted February 6, 2009 Share Posted February 6, 2009 <?php $string = "test this"; $check = substr($string, 0, 6); if (strtolower($check) != "http://") { echo 'The price is wrong BOB'; }else { echo 'ok...'; } ?> substr would be your huckleberry. edit: Changed 7 to a 6. Quote Link to comment https://forums.phpfreaks.com/topic/144111-check-that-string-has-http-at-the-start/#findComment-756170 Share on other sites More sharing options...
Maq Posted February 6, 2009 Share Posted February 6, 2009 $string = "http://www.google.com"; echo (substr($string, 0, 7)=="http://" ? "begins with" : "does not"; premiso beat me to it but here's mine anyway. Quote Link to comment https://forums.phpfreaks.com/topic/144111-check-that-string-has-http-at-the-start/#findComment-756171 Share on other sites More sharing options...
premiso Posted February 6, 2009 Share Posted February 6, 2009 $string = "http://www.google.com"; echo (substr($string, 0, 7)=="http://" ? "begins with" : "does not"; premiso beat me to it but here's mine anyway. Just a correction (I had it wrong in mine) the 7 should be 6, since substr it is 0 based. Quote Link to comment https://forums.phpfreaks.com/topic/144111-check-that-string-has-http-at-the-start/#findComment-756173 Share on other sites More sharing options...
Maq Posted February 6, 2009 Share Posted February 6, 2009 Oh yeah 6, thanks And I never compared it to anything! Quote Link to comment https://forums.phpfreaks.com/topic/144111-check-that-string-has-http-at-the-start/#findComment-756174 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.