Eye of the Dragon
$19.99
Minimum price
$25.00
Suggested price

Eye of the Dragon

PHP Strings via. Laravel

About the Book

Working with multibyte strings, Unicode, and UTF-8 can feel intimidating when writing PHP. Eye of the Dragon: PHP Strings via. Laravel offers a guided experience navigating the different techniques to properly work with and manage multibyte strings. The book also offers extensive discussions around the Laravel string helper methods to provide a familiar reference point while navigating the intricacies of string and text manipulation.

Through hundreds of hand-crafted examples and in-depth discussions, you will learn how to:

  • Read and write multibyte strings using PHP
  • Safely loop through the characters of a multibyte string
  • Work with over sixty Laravel string helper methods and fluent strings
  • Manage documents with a variety of different line-ending styles
  • Convert string positions to line and column numbers (and back)
  • And so much more

This book is still a work in progress, but you can look forward to the following chapters and discussions in the future:

  • Advanced techniques for splitting strings into arrays
  • Working with HTML, Markdown, and related strings
  • An in-depth look at regular expressions, going beyond practical examples to develop an understanding of what they are, how they work, and how we can benefit from them.

Because this book is still a work in progress, feel free to suggest topics that interest you, and they may just make it into a future version!

  • Share this book

  • Categories

    • Laravel
    • PHP
    • Computers and Programming
    • Software Engineering
    • Web Development
  • Feedback

    Email the Author(s)

About the Author

Johnathon Koster
Johnathon Koster

Hello, there!

My name is John Koster, and I have over fifteen years of professional software development. I've worked on a wide range of projects over the years, from simple websites and critical government reporting applications all the way to high-performance telematics solutions.

During my downtime, I enjoy working on open-source projects, writing posts on my blog, and contributing to the Laravel and Statamic ecosystems.

Some of the recent open-source projects I've worked on include:

  • blade-parser-typescript - a Laravel Blade parser, formatter, reflection library, and linter, written in TypeScript
  • Antlers Toolbox - a Visual Studio Code extension providing syntax highlighting, code auto-complete, intelligent refactoring, and project-aware assistance for Statamic developers
  • Antlers Runtime - an advanced PHP templating engine for the Statamic CMS platform
  • Proteus - a Laravel package that makes it simple to read, write, and modify Laravel configuration files from your application code
  • Primitives - a PHP library that safely parses input strings into native PHP types (string, bool, arrays, etc.) and can optionally be configured with a sandbox for method evaluation


Table of Contents

  • PHP Version
  • Laravel Version
  • Symbols Used In This Book
  • 1 What are Strings
    • 1.1 A Brief History of Character Encodings
    • 1.2 Unicode and UTF-8
    • 1.3 Implementing Uppercase and Lowercase Functions
    • 1.4 Iterating Multibyte Strings
    • 1.5 Accessing Individual Characters in a UTF-8 String
    • 1.6 Managing Character Encodings
    • 1.7 Types of PHP Strings
    • 1.8 Backticks and Template Strings
    • 1.9 The Laravel String Helpers
  • 2 Fluent Strings
    • 2.1 Converting Fluent String Objects to Strings
    • 2.2 Conditional String Logic
  • 3 The Formatting Helper Methods
    • 3.1 Formatting Strings with camelCasing
    • 3.2 Formatting Headlines
    • 3.3 Formatting Strings with "kebab-casing"
    • 3.4 Lowercasing the First Character of a String
    • 3.5 Creating Lowercase Variants of a String
    • 3.6 Reversing the Characters of a String
    • 3.7 Creating a URL from a Title
    • 3.8 Formatting Strings with snake_casing
    • 3.9 Removing Extra Whitespace from a String
    • 3.10 Formatting Strings with StudlyCasing
    • 3.11 Formatting Strings with Title Casing
    • 3.12 Upperacsing the First Character of a String
    • 3.13 Generating Upper Cased Variants of Strings
    • 3.14 Counting the Number of Words in a String
  • 4 The Logical Helper Methods
    • 4.1 Checking If a String Contains Another String
    • 4.2 Checking If a String Contains Multiple Substrings
    • 4.3 Checking If a String Contains Another String
    • 4.4 Checking If a String Starts with Another String
    • 4.5 Checking If a String Contains Only ASCII Characters
  • 5 The Construction Helper Methods
    • 5.1 Transliterating Characters to ASCII
      • Language Codes
    • 5.2 Generating Excerpts of Text
    • 5.3 Ensuring a String Always Ends with a Given String
    • 5.4 Calculating String Length
    • 5.5 Truncating Strings
    • 5.6 Obscuring Parts of a String
      • You Probably Shouldn't Store Credit Card Numbers
    • 5.7 Generating Pseudo-Random Strings
    • 5.8 Removing Substrings or Characters from Strings
    • 5.9 Repeating Strings and Characters
    • 5.10 Replacing Substrings
    • 5.11 Sequentially Replacing Substrings in a String
    • 5.12 Replacing the First Occurrence of a Substring or Character
    • 5.13 Replacing the Last Occurrence of a Substring or Character
    • 5.14 Ensuring Strings Always Begin with a Specific Prefix
    • 5.15 Replacing a Key/Value Pair of Strings within a String
    • 5.16 Splitting Strings on Uppercase Characters
  • 6 The Extraction Helper Methods
    • 6.1 Returning Part of a String after Another String or Character
    • 6.2 Returning a Substring after the Last Occurrence of a String or Character
    • 6.3 Returning Part of a String before Another String or Character
    • 6.4 Retrieving All Content before the Last Occurrence of a Substring or Character
    • 6.5 Retrieving Content between Two Search Strings
    • 6.6 Retrieving the Smallest Amount of Content between Two Search Strings
    • 6.7 Limiting the Number of Words in a String
    • 6.8 Getting Portions of a String
    • 6.9 Counting Occurrences of a Search String
    • 6.10 Replacing Strings within a Portion of an Existing String
  • 7 Padding Strings
    • 7.1 Padding the Beginning of Strings
    • 7.2 Padding the End of Strings
    • 7.3 Padding Both Sides of a String
  • 8 String Translations; Singular and Plural Word Forms
    • 8.1 Working with Variable Replacements
    • 8.2 Managing Ranges of Items
    • 8.3 Singular and Plural Word Forms
  • 9 Extending Strings with Macros and Mixins
  • 10 Lines and Words
    • 10.1 Positions, Lines, and Columns
    • 10.2 Splitting Strings into Words
    • 10.3 Counting Word Occurrences
    • 10.4 Finding Frequent and Repeated Words
    • 10.5 Stop Words
    • 10.6 Constructing Initialisms and Acronyms
    • 10.7 Calculating Estimated Reading Time
  • 11 More Lines and Words
    • 11.1 Locating Words at Arbitrary Positions
    • 11.2 Locating Neighboring Words and Characters
    • 11.3 Retrieving Adjacent Lines
    • 11.4 Managing Text Indentation
    • 11.5 Implementing an IndentationManager Class
  • 12 Writing a Gherkin Parser
    • 12.1 Modeling Gherkin
    • 12.2 A Gherkin Lexer
    • 12.3 Implementing Our Gherkin Parser
      • Parsing Gherkin Comments
      • Parsing Names
      • Parsing Step Text
      • Parsing Free-Form Gherkin Descriptions
      • Parsing Scenario Tags
      • Parsing Step Parameters
      • Parsing Doc Strings
      • Parsing Gherkin Data Tables
      • Parsing Scenario Examples
      • Parsing Steps
      • Parsing a Single Scenario and Background
      • Parsing Scenario Outlines and Templates
      • Parsing a Single Rule and Multiple Rules
      • Parsing Features
    • 12.4 Adding Localization Support to the Gherkin Parser
    • 12.5 Other Applications of Indentation-Based Parsers
  • 13 Markov Chains and Text Generation
    • 13.1 Writing a Markov Text Generator
    • 13.2 Weighted Randomized Selection
    • 13.3 Improving our Text Generator
  • 14 Fixed Width Data Parsing
    • 14.1 Managing Data Conversions
    • 14.2 Updating an Individual Record's Values
    • 14.3 Techniques for Managing Text Truncation
  • Appendix A: UTF-8 String Iterator Implementation
  • Appendix B: CharacterPositionLocator Implementation
  • Appendix C: IndentationManager Implementation
  • Appendix D: Gherkin Parser Implementation
  • Appendix E: Markov Chain Implementation

Causes Supported

The Innocence Project

Help Free the Innocent
http://www.innocenceproject.org

The Innocence Project provides pro-bono post conviction legal assistance to individuals who are seeking to prove their innocence with DNA testing and works to enact the reforms needed to prevent wrongful conviction and incarceration.

The Innocence Project was founded in 1992 by Barry C. Scheck and Peter J. Neufeld at the Benjamin N. Cardozo School of Law at Yeshiva University to assist prisoners who could be proven innocent through DNA testing. To date, more than 335 people in the United States have been exonerated by DNA testing, including 20 who served time on death row. The Innocence Project’s full-time staff attorneys and Cardozo clinic students provide direct representation or critical assistance in most of these cases. The Innocence Project’s groundbreaking use of DNA technology to free innocent people has provided irrefutable proof that wrongful convictions are not isolated or rare events but instead arise from systemic defects. Now an independent nonprofit organization closely affiliated with Cardozo School of Law at Yeshiva University, the Innocence Project’s mission is nothing less than to free the staggering numbers of innocent people who remain incarcerated and to bring substantive reform to the system responsible for their unjust imprisonment.

The Leanpub 60-day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms

Do Well. Do Good.

Authors have earned$11,952,850writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub