Forum Moderators: coopster
A couple of pointers...
In most web apps that input a URL into a database, unless you're carefull upfront you normally end up with either "http://www.example.com" or just "www.example.com". It depends on what validation has been done when the field value was input.
Secondly, it is perfectly valid for a URL to contain the @ character - so you have to be careful when trying to distinquish between a URL and an email address.
Anyway, having said that; I would use a "standard" email verification regexp. If it passes, render the field as an email address, if it fails, render the value as a URL.
So, your input from the db is:
$something
and you want to create
$field
which is the HTML to output to the client, then somethign like:
<?php$something = "someone@example.com";
$field = "";
if ($something)
{
if (eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$", $something))
{
$something = htmlentities($something,"ENT_QUOTES");
$field = "<a href='mailto:".$something."'>".$something."</a>";
}
else
{
$something = htmlentities($something,"ENT_QUOTES");
if (substr($something,0,4)<>"http")
{
$something = "http://".$something;
}
$field = "<a href='".$something."'>".$something."</a>";
}
}echo $field;
?>
(tested very briefly, but should be ok!)
Here's my latest stab at the line it's on:
<p>CustodianMail: <a href="<?php if ($row_rsTest['custodian'] LIKE '%@%'){echo mailto:$row_rsTest['custodian']);} else {echo $row_rsTest['custodian'];}?>"><?php echo $row_rsTest['custodian'];?></a></p>
Could it be that I'm not testing for an empty string as well?
maybe try
$emailtest = strstr [php.net]($email, '@');
if ($emailtest!= false) {
//echo your email stuff
} else {
//echo your domain stuff
}