Jump to content

strpos with if statement not working


barniegilly

Recommended Posts

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);
                  }

                     ?>

Link to comment
https://forums.phpfreaks.com/topic/246053-strpos-with-if-statement-not-working/
Share on other sites

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);

}

 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.