isset and string length

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Technocrat
Forum Contributor
Posts: 127
Joined: Thu Oct 20, 2005 7:01 pm

isset and string length

Post by Technocrat »

I was looking though a book today and I found this line:

As of PHP 4.3.10 you can use a little know feature of isset to check to see if a string offset is present.

In there example they have:

Code: Select all

//$_POST[$k] is an address field
//$v = 255

if (!empty($_POST[$k]) && isset($_POST[$k]{$v + 1})) {
    exit("{$k} is longer then the allowed {$v} length");
}
But no matter what I try it comes back as false in everything I have tried. Has anyone used this before and is there a trick to it?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

something like this should give you some insight:

Code: Select all

$string = "this is my string";
for($i=0;$i<strlen($string)+1;$i++)
{
	if(isset($string{$i}))
		echo $string{$i}."<br>";
	else
		echo "end of string met";
	
}
Post Reply