Trongate PHP Framework Docs
Introduction
Basic Concepts
Understanding Routing
Intercepting Requests
Module Fundamentals
Database Operations
Templates
Helpers
Form Handling
Working With Files
Image Manipulation
Working With Dates & Times
Authorization & Authentication
Tips And Best Practices

String Helpers

Trongate ships with a compact suite of pure PHP functions for everyday text-work. No configuration, no classes, no overhead - just reliable helpers you can call from any controller, model or view.


Available Functions

  • - pull text between two markers
  • - sanitize names and usernames
  • - clean general text input
  • - return the final segment
  • - generate cryptographically secure random strings
  • - format numbers as prices
  • - escape output for HTML, JSON, JavaScript and XML
  • - strip blocks of HTML by pattern
  • - remove text between markers
  • - convert HTML blocks based on rules
  • - clean filenames safely
  • - limit by characters
  • - limit by words
  • - generate URL - friendly slugs

Truncate Text

The function cuts by characters. The function cuts by words.


Get the Final Segment

The function returns the final portion of a string using a chosen delimiter.


Extract or Remove Text Between Markers

The function finds the first matching pair of delimiters and returns what is inside.

The removes text between markers. You may remove a single match or all matches.


Prices

The function formats numbers using commas, removes unnecessary decimals and optionally prepends a currency symbol.


Slugs and Safe Filenames

The function creates a URL - friendly slug. If the intl extension is loaded, it transliterates non-Latin characters.

The function cleans filenames, preserves extensions and handles international characters safely.


Safe Output

The function escapes strings for HTML, JSON, JavaScript, XML or attribute contexts. Always wrap untrusted content before sending it to the browser.

Security tip: If it came from a user, run it through before outputting it.


Random Strings

The produces cryptographically secure random strings, avoiding confusing characters such as 0, O, 1 and l.


HTML Conversion Helpers

The function swaps one block of HTML tags for another, preserving the enclosed content.

The function removes blocks of HTML entirely.


Filtering Input (Content Normalizing)

Trongate offers helper functions that help you normalize text or enforce formatting rules before storing data. These functions are not security filters and should not be used as a substitute for output escaping. Instead, they are useful when you want predictable, well-formed text in your database.

The function removes disallowed HTML tags while preserving the ones you specify. This is useful for bios, descriptions and other user text where you want to allow some formatting but prevent unwanted code.

The function is designed for usernames, screen names and full names. It strips tags and limits characters to a safe, readable subset, optionally allowing custom additional characters.