[web] PHP syntax question
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.
Hey Dave,
I'm a stupid noob:
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.
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.
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement