Page 1 of 1

isset and string length

Posted: Thu Oct 05, 2006 10:54 am
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?

Posted: Thu Oct 05, 2006 11:12 am
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";
	
}