XMF Cookbook
  • Introduction
  • XMF Cookbook
  • Basic Ingredients
    • Namespaces
    • Autoloading
    • Debugging
    • Forward Compatibility
  • Recipes
    • Introducing Module Helpers
    • Using the Permission Helper
      • Checking Permissions
      • Managing Item Permissions
    • Using the Session Helper
    • Using JSON Web Tokens
    • Altering Database Tables
    • Migrating a Module's Database
    • Loading Initial Data
    • Module Admin Pages
      • Hide and Seek with Icons
      • Standard Admin Pages
    • Manage Metadata
    • Highlighting Content
  • Reference
    • Assert
      • Assertions
    • Database
      • Migrate
      • TableLoad
      • Tables
        • Getting Started
        • Table Operations
        • Working with Columns
        • Working with Indexes
        • Changing Table Data
        • Interacting with the Work Queue
        • Error Info and Debugging
    • Debug
    • FilterInput
    • Highlighter
    • IPAddress
    • Jwt
      • JsonWebToken
      • KeyFactory
      • TokenFactory
      • TokenReader
    • Key
      • ArrayStorage
      • Basic
      • FileStorage
      • KeyAbstract
      • StorageInterface
    • Language
    • Metagen
      • Extracting Data
      • Applying Data
    • Module
      • Admin
      • Helper
      • Helper
        • AbstractHelper
        • Cache
        • GenericHelper
        • Permission
        • Session
    • ProxyCheck
    • Random
    • Request
    • StopWords
    • Uuid
    • Yaml
  • Credits
  • License:
  • Table of Content
Powered by GitBook
On this page
  1. Reference

Highlighter

Xmf\Highlighter is a class used to highlight terms in text. It's most common use is highlighting search terms in content.

Highlighter::apply($words, $body, $pre, $post)

Apply a highlight to any occurrences of $words found in the $body text, surrounding each with $pre in front and $post behind. Considers only occurrences of words outside of HTML tags.

$words is an array of strings to find and highlight. If it is a string, it is treated as a set of space delimited words and converted to an array of strings.

$body is text to which highlight is to be applied.

$pre is the markup to be used to start a highlight. By default, it is "".

$post is the markup to be used to start a highlight. By default, it is "</strong>".

The highlighted version of $body is returned.

PreviousFilterInputNextIPAddress

Last updated 6 years ago