Jump to content

Recommended Posts

k it's  a bit messy rigt now from bug testing but here it is

 

                $y = 1;
	$x = 0;
	$tempCount = 'x';
	$prev = 'y';

	$hostPortion = explode(".", $hostName);

	while($x != 1){
		echo $prev." = prev before equal tempcount <BR>";
		echo $tempCount." = tempcount before equal prev <BR>";

		$prev = $tempCount;

		echo $prev." = prev after equal tempcount <BR>";
		echo $tempCount." = tempcount after equal prev <BR><BR>";


		if($hostPortion == false){
			echo "hostportion was false and is now exiting the loop";
			$x = 1;
			$count = $y;

		}
		else{
			$tempCount = $hostPortion[$y];
		}
		echo "host portion after false if = ".$hostPortion[$y]."<BR>";
		echo $x." = x after false if statement <BR><BR>";

		echo $tempCount." = tempcount after = host protion <BR><BR>";

		echo $prev." = prev before if <BR>";
		echo $tempCount." = tempcount before if <BR>";
		echo $x." = x before if statement <BR>";
		/*
		if($prev == $tempCount){

			$count = $y;
			$x = 1;
		}
		*/

		echo $x." = x after if statement <BR><BR>";

		$y++;
		echo $y." = y at end of loop<BR>";
	}



	echo $hostPortion[$count]."<BR><BR>";


if($hostPortion == false){
			echo "hostportion was false and is now exiting the loop";
			$x = 1;
			$count = $y;

		}
		else{
			$tempCount = $hostPortion[$y];
		}
		echo "host portion after false if = ".$hostPortion[$y]."<BR>";

 

when it try's to use $hostPortion[$y]

 

pretty much it's getting to the number 6.  but that's an error but it still has to run that sixth time in order to make $prev = $tempCount

 

sorry if this is a bit confusing

the problem with the code just above is that it's not returning false.....just notifying.

 

what i'm trying to do overall is determine what the ending of the host name of a user is....ie.  .com  .ca .org  excetera. 

 

since all host name seem to have a different number of .'s i need to run the loop an unknown amount of time to find the last one.  at which point i'm getting the notify error

You can stop the notice by checking if the variable is set first before using it.

If you want to do it inline you can use the ternary operator,

 

<?php
echo "host portion after false if = ".(isset($hostPortion[$y]) ? $hostPortion[$y] : '')."<BR>";
?>

 

But the way you're going about this is more than you need.

The below code will give you the TLD of the host.

 

<?php

$host = 'www.example.com';
echo substr($host,  strrpos($host, '.'));

?>

hey thanks.  the first bit of code you gave did'nt work, but suggestion on how to do it worked well.  may i ask exactly what it's doing when i say   

 

echo substr($hostName, strrpos($hostName, '.'));

 

 

thanks

 

See the links for more information on the parameters.

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.