Learn how to use a regex to extract the first number of complete sentences from a longer text.
- [David] Hi, I'm David Powers and welcome…to this week's edition of php Tips, Tricks and Techniques,…designed to help you become a smarter,…more productive php developer.…This week I want to look at how to split a string…using a regular expression.…This can be useful, for example,…to extract complete sentences from the beginning…of a long piece of text.…You can then display the first few sentences…and add a link to the rest.…The exercise files for this video…contain this extract from Alice in Wonderland.…And the problem soon becomes obvious.…
php has no concept of what constitutes a sentence,…and you can't simply rely on the sentences…ending with a period.…For example, this sentence ends with an exclamation mark,…here we've got a question mark followed by a closing quote,…and then down here we've got a period…followed by a closing parenthesis.…And that's why we need a regular expression.…So, let's switch to this other file…where I've started building the script.…It begins by getting the contents of that text file…
Note: The exercise files are free to all members. The code is commented to enhance your learning, but you will need database connectivity for some files to run as intended.
Skill Level Intermediate
PHP: Managing Persistent Sessionswith David Powers2h 41m Intermediate
New this Week:
1. Weekly Episodes
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.