Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP File Handling with PHP Parsing Specific Formats Reading JSON

Why use ' ' as second parameter in strpos?

In the video, the teacher retrieved sub string of the description by using:

substr($book->book_description, 0, strpos($book->book_description, ' ', 500)) . "...";

to show the part of characters above 500 as '...' But I dont understand why in the strpos function the second parameter is a space? what does that mean?

Thank you.

1 Answer

She explains in the video @ 5:27

Then for the endpoint I could just use 500, but it might cut off in the middle of the word. Instead I'll use the string position and look for the next space after 500 characters.

Syntax. strpos(string,find,start)