Wierd Syntax

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
LarryKreeger
Forum Newbie
Posts: 4
Joined: Mon Dec 21, 2009 5:53 pm

Wierd Syntax

Post by LarryKreeger »

I've been working with LDAPS to reset a users password and password has to be in UTF-8 so
the code reads through an array byte by byte and does this.

$newPassword = "{$Password[$i]}\000";

1. What is the "\" doing? It's not a division operator. Somehow it's appending 3 zeros to the character.
2. Why the "{" brackets? This isn't a function.

The code works but I would just like to understand why. :)
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: Wierd Syntax

Post by daedalus__ »

when you use a double quote string you can encapsulate variable names in silly brackets to make sure the parser knows its a variable.

like if you say

Code: Select all

 
echo "lol omg __$wiener__";
 
it'll think that $wiener__ is the variable name so you wrap it

http://us.php.net/manual/en/language.ty ... ng.parsing
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Wierd Syntax

Post by AbraCadaver »

Yes, and since you're using an array with [] sometimes it can not be interpreted as a var and it is also easier to read. \ is an esacape character. \n is a newline, \r is a return character, \000 is a null character. Dunno why they are using it there. It may have some significance in LDAP.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Wierd Syntax

Post by s.dot »

This:

Code: Select all

$newPassword = "{$Password[$i]}\000";
is the same as

Code: Select all

$newPassword = $Password[$i] . "\000";
is the same as

Code: Select all

$newPassword = "" . $Password[$i] . "\000";
Just different ways to encapsulate an array index within a string.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: Wierd Syntax

Post by daedalus__ »

AbraCadaver wrote:\000 is a null character.
lol i was so mad i couldn't remember that.
LarryKreeger
Forum Newbie
Posts: 4
Joined: Mon Dec 21, 2009 5:53 pm

Re: Wierd Syntax

Post by LarryKreeger »

Thanks guys. The {} makes absolute sense. However, we finally found more about the \000. Apparently that is an escape sequence that says the string in front of it is octal. At least that is my interpretation of what I've been reading. We found that in some PERL documentation but it fits with what the PHP is doing. Now I'm going to get an extra large cup of coffee because I need it.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Wierd Syntax

Post by AbraCadaver »

LarryKreeger wrote:Thanks guys. The {} makes absolute sense. However, we finally found more about the \000. Apparently that is an escape sequence that says the string in front of it is octal. At least that is my interpretation of what I've been reading. We found that in some PERL documentation but it fits with what the PHP is doing. Now I'm going to get an extra large cup of coffee because I need it.
Yes, \000 is the octal escape sequence for a null byte. \x00 would be the hexadecimal equivalent. Many times \000 would be the decimal code, \o000 would be the octal and \x000 would be the hex, but PHP only supports the \000 octal form and \x000 hex form.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
LarryKreeger
Forum Newbie
Posts: 4
Joined: Mon Dec 21, 2009 5:53 pm

Re: Wierd Syntax

Post by LarryKreeger »

Ok obviously I haven't had enough coffee.
Sooooo you can store octals by \333 or \011 or whatever but \000 is reserved by unicode to denote the end of the character because unicode characters are variable lengths.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Wierd Syntax

Post by Weirdan »

LarryKreeger wrote:Sooooo you can store octals by \333 or \011 or whatever but \000 is reserved by unicode to denote the end of the character because unicode characters are variable lengths.
Null character has no special significance to either Unicode or to its (most widespread) UTF-8 encoding. Sidenote: Unicode (Universal Character Set to be precise) is not encoding, it's character set, and depending on particular encoding its characters could be encoded in variable or constant (bit)lengths.
LarryKreeger
Forum Newbie
Posts: 4
Joined: Mon Dec 21, 2009 5:53 pm

Re: Wierd Syntax

Post by LarryKreeger »

Thanks guys that helped a lot.
Post Reply