Collegeboox Posted November 6, 2011 Share Posted November 6, 2011 Can someone write me some simple code to check to see if the url has the word "soundcloud" in them. This is what I want to do.... This is my code now... echo " <h3> $title - $author</h3> </br> <iframe width='640' height='360' src='$link' frameborder='0' allowfullscreen></iframe> </br> </br> $message </br> <font color='#8b8d9b' size='1'>Posted By: $username $date</font> </br></br></br></br></br> "; However I want to pull the link value out of the database and see if it contains the word "soundcloud" and if it does do this...(note the height is changed) echo " <h3> $title - $author</h3> </br> <iframe width='640' height='100' src='$link' frameborder='0' allowfullscreen></iframe> </br> </br> $message </br> <font color='#8b8d9b' size='1'>Posted By: $username $date</font> </br></br></br></br></br> "; Any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/250576-if-statement-contains-value/ Share on other sites More sharing options...
trq Posted November 7, 2011 Share Posted November 7, 2011 Were not here to write code for people. See strpos. Quote Link to comment https://forums.phpfreaks.com/topic/250576-if-statement-contains-value/#findComment-1285732 Share on other sites More sharing options...
Collegeboox Posted November 7, 2011 Author Share Posted November 7, 2011 I have posted 2 other times asking for help and I am not getting any help from anyone they just keep telling me why didnt I do it this way why didnt I do it that way...So I thought it would just be easier to just ask if someone could tell me the code. Quote Link to comment https://forums.phpfreaks.com/topic/250576-if-statement-contains-value/#findComment-1285757 Share on other sites More sharing options...
trq Posted November 7, 2011 Share Posted November 7, 2011 There are examples at the link I provided. Quote Link to comment https://forums.phpfreaks.com/topic/250576-if-statement-contains-value/#findComment-1285762 Share on other sites More sharing options...
haku Posted November 7, 2011 Share Posted November 7, 2011 if(strpos($link, 'soundcloud') !== FALSE) Quote Link to comment https://forums.phpfreaks.com/topic/250576-if-statement-contains-value/#findComment-1285763 Share on other sites More sharing options...
Collegeboox Posted November 7, 2011 Author Share Posted November 7, 2011 if(strpos($link, 'soundcloud') !== FALSE) So this is saying if the string $link contains soundcloud then it does not equal false? So I could do... if(strpos($link, 'soundcloud') !== FALSE) echo "" else echo"" Correct or no?? Quote Link to comment https://forums.phpfreaks.com/topic/250576-if-statement-contains-value/#findComment-1285780 Share on other sites More sharing options...
haku Posted November 7, 2011 Share Posted November 7, 2011 strpos() returns the index of the starting position of the found string. That is to say, it returns the position of the first letter of the found string, or FALSE if the string is not found. However, indexes start at zero, so if the string is found at the very start, it will return zero, and zero is equivalent to false. So you have to do a test to make sure it's a boolean false, and not a zero false. This is done using the three equals signs: ===, or if you want to test to make sure it's not the boolean false, you use an exclamation with two equals signs: !== And yes, what you wrote is correct. Quote Link to comment https://forums.phpfreaks.com/topic/250576-if-statement-contains-value/#findComment-1285782 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.