Monkuar Posted March 17, 2012 Share Posted March 17, 2012 I need to use preg_match, to check if "mywebsite.com" exists inside a string. how would do I go about that? Im not looking to validate urls, im just looking to see if the string has mywebsite.com in it, if true, i can use w/e, or return false. Thanks hmm would strpos or strmatch work ? Something like this if (preg_match("/http://mysite.com/i", "GOBBLYBLUETEXTHEREBLABLAH")) { echo "A match was found."; } else { echo "A match was not found."; } actually would that work?, lmk ima be testing Quote Link to comment https://forums.phpfreaks.com/topic/259138-preg_matching-a-website-address/ Share on other sites More sharing options...
SaCH Posted March 17, 2012 Share Posted March 17, 2012 Try this if (stristr("http://mysite.com", "GOBBLYBLUETEXTHEREBLABLAH")) { echo "A match was found."; } else { echo "A match was not found."; } Quote Link to comment https://forums.phpfreaks.com/topic/259138-preg_matching-a-website-address/#findComment-1328480 Share on other sites More sharing options...
Pikachu2000 Posted March 18, 2012 Share Posted March 18, 2012 stripos would be faster and less resource intensive. if ( stripos($haystack, $needle) === FALSE ) { // not found } else { // found } Quote Link to comment https://forums.phpfreaks.com/topic/259138-preg_matching-a-website-address/#findComment-1328660 Share on other sites More sharing options...
SaCH Posted March 18, 2012 Share Posted March 18, 2012 stripos would be faster and less resource intensive. if ( stripos($haystack, $needle) === FALSE ) { // not found } else { // found } Sir, that means my example which is used by stristr() is not sufficient ? Quote Link to comment https://forums.phpfreaks.com/topic/259138-preg_matching-a-website-address/#findComment-1328695 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.