DEV Community

Scott Robertson
Scott Robertson

Posted on • Originally published at blog.scottrobertson.me on

Select A Character in a String with PHP

I love finding little thing in PHP that I did not know before. They are generally not important or advanced but it's still very interesting. Here are a few I found recently:

Select a character with a string without using substr etc:

$string = '1234';
echo $string[1]; // 2

Enter fullscreen mode Exit fullscreen mode

Another one i found was "__halt_compiler", it's one of the ones i have no real use for but interesting nonetheless. It basically stops the PHP compiler so you can just output HTML from then on without any more server resources being used.

__halt_compiler();

Enter fullscreen mode Exit fullscreen mode

I shall no doubt find a lot more of these, and i will have no use for any of them more than likely.

Top comments (0)