PHP String Functions Reference
Decide whether an operation works on bytes, Unicode characters, literal text or a pattern. That choice should follow the field’s encoding and meaning.
How it works
Many traditional string functions work on bytes, even when a browser later displays the result as text. Use mbstring with an explicit encoding where its contract fits and a grapheme-aware API where visible editing boundaries require it. Literal replacement, regex replacement and output encoding are distinct tasks. A helper’s presence in the inventory is not permission to use a deprecated hash or encoding conversion in new security-sensitive code.
Run it locally
Run this complete source locally with PHP 8.2 or newer. Save it using the filename shown and run the command below. PHP is not currently available in Bhylu’s browser playground. Apache and MySQL are not needed for an ordinary CLI example.
php -l ref-text.php
php ref-text.phpDownload this source as a local PHP lab file. Keep lab files separate from the Bhylu project and production data.
Example
<?php
declare(strict_types=1);
$name = " Hand drill ";
$clean = trim($name);
echo str_starts_with($clean,"Hand") ? "Prefix matches\n" : "No prefix\n";
echo str_replace("drill","saw",$clean), "\n";
Expected result
Prefix matches
Hand sawThe boundary trim and literal replacement are separate steps. The original variable still holds the raw spaces. Neither result is automatically safe to insert into every output context, and this ASCII search does not establish a language-specific case or normalisation policy.
Contracts to check
| API or term | Important boundary |
|---|---|
| strlen, substr, strpos | Byte-oriented boundaries; strict false checks for search failure. |
| mb_strlen, mb_substr, mb_strtolower | Encoding-aware operations require mbstring and a stated encoding. |
| trim, str_replace, explode, implode | Literal boundary/replacement/separator contracts. |
| htmlspecialchars, htmlentities | HTML output encoding, not SQL/JavaScript/URL authorisation. |
| md5, sha1, crypt | Do not substitute fast hashes for password_hash/password_verify. |
| utf8_encode, utf8_decode | Deprecated legacy ISO-8859-1 conversions; choose explicit source/destination encodings. |
Related API names
This alphabetic inventory helps locate related calls. Availability was checked in the review runtime; it is not a recommendation to use every API or a claim that every overload/function was executed. Read the official entry for version, extension, failure and security details.
| Name | Review-runtime status |
|---|---|
addcslashes() | Available in the PHP review runtime |
addslashes() | Available in the PHP review runtime |
bin2hex() | Available in the PHP review runtime |
chop() | Available in the PHP review runtime |
chr() | Available in the PHP review runtime |
chunk_split() | Available in the PHP review runtime |
convert_cyr_string() | Not available in this review runtime; check version and extension requirements |
convert_uudecode() | Available in the PHP review runtime |
convert_uuencode() | Available in the PHP review runtime |
count_chars() | Available in the PHP review runtime |
crc32() | Available in the PHP review runtime |
crypt() | Available in the PHP review runtime |
echo | Language construct |
explode() | Available in the PHP review runtime |
fprint() | Not available in this review runtime; check version and extension requirements |
get_html_translation_table() | Available in the PHP review runtime |
hebrev() | Available in the PHP review runtime |
hebrevc() | Not available in this review runtime; check version and extension requirements |
hex2bin() | Available in the PHP review runtime |
html_entity_decode() | Available in the PHP review runtime |
htmlentities() | Available in the PHP review runtime |
htmlspecialchars() | Available in the PHP review runtime |
htmlspecialchars_decode() | Available in the PHP review runtime |
implode() | Available in the PHP review runtime |
join() | Available in the PHP review runtime |
lcfirst() | Available in the PHP review runtime |
levenshtein() | Available in the PHP review runtime |
localeconv() | Available in the PHP review runtime |
ltrim() | Available in the PHP review runtime |
md5() | Available in the PHP review runtime |
md5_file() | Available in the PHP review runtime |
metaphone() | Available in the PHP review runtime |
money_format() | Not available in this review runtime; check version and extension requirements |
nl_langinfo() | Not available in this review runtime; check version and extension requirements |
nl2br() | Available in the PHP review runtime |
number_format() | Available in the PHP review runtime |
ord() | Available in the PHP review runtime |
parse_str() | Available in the PHP review runtime |
print | Language construct |
printf() | Available in the PHP review runtime |
quoted_printable_decode() | Available in the PHP review runtime |
quoted_printable_encode() | Available in the PHP review runtime |
quotemeta() | Available in the PHP review runtime |
rtrim() | Available in the PHP review runtime |
setlocale() | Available in the PHP review runtime |
sha1() | Available in the PHP review runtime |
sha1_file() | Available in the PHP review runtime |
similar_text() | Available in the PHP review runtime |
soundex() | Available in the PHP review runtime |
sprintf() | Available in the PHP review runtime |
sscanf() | Available in the PHP review runtime |
str_contains() | Available in the PHP review runtime |
str_ends_with() | Available in the PHP review runtime |
str_getcsv() | Available in the PHP review runtime |
str_ireplace() | Available in the PHP review runtime |
str_pad() | Available in the PHP review runtime |
str_repeat() | Available in the PHP review runtime |
str_replace() | Available in the PHP review runtime |
str_rot13() | Available in the PHP review runtime |
str_shuffle() | Available in the PHP review runtime |
str_split() | Available in the PHP review runtime |
str_starts_with() | Available in the PHP review runtime |
str_word_count() | Available in the PHP review runtime |
strcasecmp() | Available in the PHP review runtime |
strchr() | Available in the PHP review runtime |
strcmp() | Available in the PHP review runtime |
strcoll() | Available in the PHP review runtime |
strcspn() | Available in the PHP review runtime |
strip_tags() | Available in the PHP review runtime |
stripcslashes() | Available in the PHP review runtime |
stripos() | Available in the PHP review runtime |
stripslashes() | Available in the PHP review runtime |
stristr() | Available in the PHP review runtime |
strlen() | Available in the PHP review runtime |
strnatcasecmp() | Available in the PHP review runtime |
strnatcmp() | Available in the PHP review runtime |
strncasecmp() | Available in the PHP review runtime |
strncmp() | Available in the PHP review runtime |
strpbrk() | Available in the PHP review runtime |
strpos() | Available in the PHP review runtime |
strrchr() | Available in the PHP review runtime |
strrev() | Available in the PHP review runtime |
strripos() | Available in the PHP review runtime |
strrpos() | Available in the PHP review runtime |
strspn() | Available in the PHP review runtime |
strstr() | Available in the PHP review runtime |
strtok() | Available in the PHP review runtime |
strtolower() | Available in the PHP review runtime |
strtoupper() | Available in the PHP review runtime |
strtr() | Available in the PHP review runtime |
substr() | Available in the PHP review runtime |
substr_compare() | Available in the PHP review runtime |
substr_count() | Available in the PHP review runtime |
substr_replace() | Available in the PHP review runtime |
trim() | Available in the PHP review runtime |
ucfirst() | Available in the PHP review runtime |
ucwords() | Available in the PHP review runtime |
vfprintf() | Available in the PHP review runtime |
vprintf() | Available in the PHP review runtime |
vsprintf() | Available in the PHP review runtime |
wordwrap() | Available in the PHP review runtime |
Check the official PHP manual for detailed version and API contracts.