Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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)