String Functions
String functions help you format, validate, and transform text content. Instead of displaying raw data that might be too long, improperly formatted, or unsafe, these functions let you clean up text, control length, and ensure content displays exactly as intended.
Why String Functions Matter
Raw text challenges:
- Post titles that are too long for card layouts
- Misbehaving HTML tags in post content:
"<p>Welcome to our site</p>" - Inconsistent capitalization in user-generated content
- Dates showing as timestamps:
1699833600instead of"November 12, 2023"
What string functions solve:
- Length control: Trim long titles to fit design layouts
- Safe display: Remove HTML tags and escape special characters
- Consistent formatting: Standardize capitalization and styling
- User-friendly dates: Convert timestamps to readable formats
Text Transformation
Change the appearance and format of your text content.
upper/lower
Convert to Uppercase / Convert to Lowercase.
- Description
- Example
- Result
upper(text) # Convert to UPPERCASE
lower(text) # Convert to lowercase
# Consistent headings
upper(post_category)
# Clean user input
lower(user_search_term)
# Brand name formatting
upper(company_name)
# "technology" → branded heading
"TECHNOLOGY"
# "WordPress TIPS" → clean search
"wordpress tips"
# "builderius" → brand consistency
"BUILDERIUS"
escape
Essential for displaying user content safely by converting HTML tags to visible text.
- Description
- Example
- Result
escape(text)
When to use:
- Display HTML code examples in tutorials
- Show user-submitted content safely
- Prevent HTML injection in comments
# Show HTML code safely
escape(code_example)
# Display user comment with HTML tags
escape(user_comment)
# Safe tutorial content
escape('<div class="example">Hello</div>')
# HTML code becomes visible text
"<div class="highlight">Code</div>"
# User's HTML shows as text, not markup
"Check out my <strong>awesome</strong> site"
# Tutorial code displayed safely
"<div class="example">Hello</div>"
Text Length and Control
Manage text length to fit your design layouts and improve readability.
count
Check text length for validation, layout decisions, and content analysis.
- Description
- Example
- Result
count(text)
When to use:
- Check if titles fit design layouts
- Validate form input lengths
- Show character counts to users
# Check title length for cards
count(post_title)
# Validate bio length
count(user_bio)
# Count characters in post content
count(post_content)
# "How to Build Better Websites" → length check
28
# "WordPress developer from Croatia" → bio length
32
# Full post content → total character count
2847
limit_characters
Control exact text length while preserving readability.
- Description
- Example
- Result
limit_characters(text, max_length, start_position)
When to use:
- Fit text into fixed-width design elements
- Create consistent card layouts
- Show text previews with exact character limits
# Card title limit
limit_characters(post_title, 50)
# Meta description preview
limit_characters(seo_description, 160)
# Short excerpt for mobile
limit_characters(post_excerpt, 80)
# "How to Build Better Websites with Modern Tools" → card fit
"How to Build Better Websites with Modern Too"
# Long description → SEO preview
"Learn advanced WordPress development techniques for building professional, scalable websites that perform well and..."
# Mobile excerpt → brief preview
"Discover the essential tools and techniques every WordPress developer needs"
limit_words
Maintain readable text flow by cutting at word boundaries instead of mid-word.
- Description
- Example
- Result
limit_words(text, word_count, start_position)
When to use:
- Create readable excerpts and previews
- Maintain text flow in card layouts
- Show consistent content lengths across posts
# Blog card excerpt
limit_words(post_content, 25)
# Featured post preview
limit_words(post_excerpt, 15)
# Category description
limit_words(category_description, 12)
# Full post → readable excerpt
"WordPress development requires understanding both frontend and backend technologies. Modern tools like Builderius help bridge this gap by providing visual development environments that work with..."
# Post excerpt → brief summary
"Learn essential WordPress development techniques for building professional websites that perform well."
# Category → short description
"Tips and tutorials for modern WordPress development and best practices."
Text Search and Validation
Find specific content within text and validate text patterns.
includes
Essential for conditional content display and search functionality.
- Description
- Example
- Result
includes(search_for, search_in)
When to use:
- Conditional content based on post titles or content
- Search result highlighting
- Category and tag filtering
# Check if post is about WordPress
includes('WordPress', post_title)
# Find tutorial posts
includes('tutorial', lower(post_content))
# Check for specific features
includes('Pro', product_name)
# "Advanced WordPress Techniques" → contains WordPress
true
# Post content mentions "step-by-step tutorial" → is tutorial
true
# "Builderius Pro Features" → is Pro version
true
match
Advanced text validation and pattern detection for complex text analysis.
- Description
- Example
- Result
match(pattern, text)
When to use:
- Validate email formats and URLs
- Extract specific text patterns
- Complex content filtering
# Check for email pattern
match('/@/', email_address)
# Find posts ending with "Tutorial"
match('/Tutorial$/', post_title)
# Check for phone number pattern
match('/\d{3}-\d{3}-\d{4}/', contact_info)
# "[email protected]" → has @ symbol
true
# "WordPress Development Tutorial" → ends with "Tutorial"
true
# "Contact: 555-123-4567" → matches phone pattern
true
Number and Currency Formatting
Transform numbers into professional, readable formats.
number_format
Make large numbers readable and format currencies consistently.
- Description
- Example
- Result
number_format(number, decimals, decimal_point, thousands_separator)
When to use:
- Display prices and financial data
- Format statistics and counts
- International number formatting
# Product price formatting
number_format(product_price, 2, '.', ',')
# Large statistics
number_format(download_count, 0, '.', ',')
# European format
number_format(price, 2, ',', '.')
# 1234.5 → professional price display
"1,234.50"
# 1234567 → readable download count
"1,234,567"
# 1234.50 → European currency format
"1.234,50"
sprintf
Create exactly formatted strings with dynamic values for consistent output.
- Description
- Example
- Result
sprintf(format_string, value1, value2, ...)
Format codes:
%s- String%d- Integer%.2f- Float with 2 decimals%%- Literal % symbol
When to use:
- Consistent currency formatting
- Template-based text generation
- Multi-language number formatting
# Currency with symbol
sprintf('$%.2f', product_price)
# Progress display
sprintf('%d%% Complete', completion_percentage)
# Complex formatting
sprintf('Order #%d - %s - $%.2f', order_id, customer_name, total)
# 19.5 → exact currency format
"$19.50"
# 85 → progress indicator
"85% Complete"
# Multiple values → formatted string
"Order #1001 - John Smith - $149.99"
Date and Time Handling
Convert timestamps to human-readable dates and parse date strings.
date
Transform WordPress timestamps into any date format you need.
- Description
- Example
- Result
date(format, timestamp)
Common formats:
'F j, Y'- November 12, 2023'M d, Y'- Nov 12, 2023'Y-m-d'- 2023-11-12'g:i A'- 2:30 PM
When to use:
- Display publication dates
- Format event dates and times
- Create consistent date styles
# Blog post date
date('F j, Y', post_timestamp)
# Event date and time
date('M j, Y \a\t g:i A', event_timestamp)
# Short date format
date('m/d/Y', modified_timestamp)
# 1699833600 → readable blog date
"November 12, 2023"
# 1699926000 → event date with time
"Nov 13, 2023 at 2:30 PM"
# 1699747200 → short format
"11/11/2023"
strtotime
Convert date strings into timestamps for calculations and comparisons.
- Description
- Example
- Result
strtotime(date_string, base_timestamp)
When to use:
- Parse user-entered dates
- Calculate relative dates
- Convert various date formats to timestamps
# Parse custom date field
strtotime(custom_event_date)
# Relative date calculation
strtotime('next month', current_timestamp)
# Parse ISO date format
strtotime('2023-11-15T14:30:00')
# "2023-11-15" → timestamp
1700006400
# Current + 1 month → future timestamp
1702425600
# ISO format → precise timestamp
1700061000
Type Conversion
Convert between different data types for calculations and formatting.
intval/floatval
Convert to Whole Number / Convert to Decimal
- Description
- Example
- Result
intval(value) # Convert to integer
floatval(value) # Convert to float/decimal
When to use:
- Clean user input for calculations
- Convert custom field values to numbers
- Ensure proper data types for math operations
# Clean user input
intval(user_age_input)
# Convert price field
floatval(custom_price_field)
# Parse string numbers
floatval(rating_average)
# "25" string → clean integer
25
# "19.99" string → decimal number
19.99
# "4.5" rating → numeric value
4.5