PHP: How to Get the First 10 Characters from a String

Join 5,000 subscribers and get a periodic digest of news, articles, and more.
By submitting your email, you agree to the Terms of Use and Privacy Policy.
PHP Logo
Lets face it, we’re not the best PHP programmers, or else we’d probably remember how to do this without having to look it up all the time, right? I mean, I’ve looked this one up so many times that I’m actually writing about it in the hopes that I’ll remember next time. Sad!
Luckily this one is really easy and our shame will be over quickly. So here’s the syntax:
If you still can’t figure it out, here’s an example:
But if you’re working with strings that could be multi-byte, like unicode strings with special characters, you should probably use mb_substr() instead, which has the same syntax:
You could also use this to get a string out of the middle somewhere by adjusting the start parameter — for example, you could grab the last few characters from the end of the string instead.
The above article may contain affiliate links, which help support CloudSavvy IT.
Facebook
Twitter
LinkedIn
Cloud wisdom in your inbox
By submitting your email, you agree to the Terms of Use and Privacy Policy.

source

Digital Strategist Chris Hood

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2021 SHAQ HAX - Proudly powered by theme Octo