barniegilly Posted August 30, 2011 Share Posted August 30, 2011 Hi I have a page pulling information from mysql table, it lists names, I have these inside a hyperlink so that where there is a website listed for that record then the user can click on the name and move to their website. Only thing is that what happens if there is not a website for that record. I wanted a script so that if there is a website address listed then it prints the hyperlink but where there is not a website address listed that only the name is printed and it is not a hyperlink. I understand that the strpos can be used for this I have written a script but it is only printing out the name even when there is a website address in the row. What is wrong? PHP Version 5.3.4 Any help very much appreciated <?php $website = $org_website; $link = 'http'; $weblink = strpos ($website,$link); if ($weblink === !false) { echo "<a href=\"$org_website;\"> FindOrganiserName($org_id); \"> FindOrganiserName($org_website); </a>"; } else { echo FindOrganiserName($org_id); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/246053-strpos-with-if-statement-not-working/ Share on other sites More sharing options...
AyKay47 Posted August 30, 2011 Share Posted August 30, 2011 $weblink === !false is not valid.. its either === FALSE or === TRUE Quote Link to comment https://forums.phpfreaks.com/topic/246053-strpos-with-if-statement-not-working/#findComment-1263658 Share on other sites More sharing options...
KevinM1 Posted August 30, 2011 Share Posted August 30, 2011 Or: if ($weblink !== false){ // do stuff } Quote Link to comment https://forums.phpfreaks.com/topic/246053-strpos-with-if-statement-not-working/#findComment-1263662 Share on other sites More sharing options...
AyKay47 Posted August 30, 2011 Share Posted August 30, 2011 yeah, whatever way you want. just not the way you executed.. Quote Link to comment https://forums.phpfreaks.com/topic/246053-strpos-with-if-statement-not-working/#findComment-1263663 Share on other sites More sharing options...
Pikachu2000 Posted August 30, 2011 Share Posted August 30, 2011 strpos() returns either an integer or FALSE, so a comparison of strpos() === TRUE will not work as expected. Quote Link to comment https://forums.phpfreaks.com/topic/246053-strpos-with-if-statement-not-working/#findComment-1263664 Share on other sites More sharing options...
barniegilly Posted August 30, 2011 Author Share Posted August 30, 2011 hi all thank you for your help this is the code that is working for me, thank you for your help <?php $website = $org_website; $link = 'http'; $weblink = strpos ($website,$link); if ($weblink !== FALSE ) { echo "<a href=\"$org_website\" target=\"_blank\"> $org_name </a>"; } else { echo FindOrganiserName($org_id); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/246053-strpos-with-if-statement-not-working/#findComment-1263676 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.