# [web] PHP syntax question

## Recommended Posts

Hi, I have a little question about a fragment of PHP I found on the net. Please don't bash me for not doing proper research, but I have a deadline to meet this evening and can't spend much time on language details, so here goes... $dir = ($path { strlen( $path ) - 1 } == '/' ) ? substr($path, 0, strlen( $path ) - 1 ) : dirname($path ); What's that syntax element called where a variable ($path) is followed with a set of braces {}? Is it an index? Sorry for the dumb question, I'm a PHP newbie. #### Share this post ##### Link to post ##### Share on other sites Hey bud, Looks to me like a regular expression, in place, in the code. Dave #### Share this post ##### Link to post ##### Share on other sites Hey Dave, I'm a stupid noob: Quote: ### String access and modification by character Characters within strings may be accessed and modified by specifying the zero-based offset of the desired character after the string in curly braces. Note: For backwards compatibility, you can still use array-brackets for the same purpose. However, this syntax is deprecated as of PHP 4. Example 11-5. Some string examples <?php // Get the first character of a string$str = 'This is a test.';
$first =$str{0};

// Get the third character of a string
$third =$str{2};

// Get the last character of a string.
$str = 'This is still a test.';$last = $str{strlen($str)-1};

// Modify the last character of a string
$str = 'Look at the sea';$str{strlen(\$str)-1} = 'e';

?>

From the PHP manual.

It's old syntax for characterwise string access.

Thanks for your help though, ++rating

An exception was thrown in Konfusius.exe: !! ace_lovegrove->rating: index out of bounds !!

Hmm... yeah, back to work.

##### Share on other sites
Hey man,

Sorry, although i know some PHP im in noway as competant in it as i am at C++, you learn something every day.

P.S. My rating hardly ever moves now!

Dave

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627657
• Total Posts
2978471

• 10
• 12
• 22
• 13
• 33