Jump to content
  • Advertisement
Sign in to follow this  
demonkoryu

[web] PHP syntax question

This topic is 4486 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!