From the course: PHP for Non-Programmers

Unlock the full course today

Join today to access over 25,200 courses taught by industry experts.

Writing your functions first

Writing your functions first - PHP Tutorial

From the course: PHP for Non-Programmers

Writing your functions first

- [Instructor] Since this project is a little bit more complicated than previous projects, let's break the requirements down into easily testable functions, starting with counting all of the words in the provided text. So we'll write our opening PHP tag, and then we'll create a function. We'll call it count words, and then we will send a variable to it called text. So this text will be the provided text. And there is a built in function called STR word count, so we'll make use of that and we'll return STR word count text. Now this function is returning a built in PHP function's results. We could theoretically just call STR word count, and it would be slightly more efficient, but having this function allows us a bit more flexibility in case we decide we want to make changes to the built-in function while still using it. Maybe we want to exclude words like a or the from the word count. And the reason that we break these…

Contents