HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to PHPVariablesData TypesOperatorsStringsArraysAssociative ArraysConditions (if / else)Loops (for / foreach / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
🔢 Numbers & Math
✍️ String
strlen()strtoupper() / strtolower()trim()str_replace()substr()explode() / implode()strpos()
📋 Array
🔁 Condition & Loop
🧩 Function
🔄 Type & Conversion
PHP›REFERENCE›String
✍️

String

Text length, transformation, splitting, and searching.

CommandDescription
strlen()Returns the number of characters.
strtoupper() / strtolower()Converts to uppercase / lowercase.
trim()Removes leading/trailing whitespace.
str_replace()Replaces a part with something else.
substr()Extracts a part of the text.
explode() / implode()Splits text into an array / joins an array into text.
strpos()Finds the position of a substring.

strlen()

Try it yourself →

Returns the number of characters.

Syntax

strlen($text)

Description

Returns the number of characters in the text.

Example

<?php
echo strlen("merhaba");

Expected output

7

When to use?

Length check (passwords, limits).

strtoupper() / strtolower()

Try it yourself →

Converts to uppercase / lowercase.

Syntax

strtoupper($text)

Description

Returns new text; does not change the original.

Example

<?php
echo strtoupper("hexlibrary");

Expected output

HEXLIBRARY

When to use?

Ignoring case sensitivity in comparisons.

trim()

Try it yourself →

Removes leading/trailing whitespace.

Syntax

trim($text)

Description

Cleans up spaces/newlines at the beginning and end of the text.

Example

<?php
echo trim("   space   ");

Expected output

space

When to use?

Cleaning form input.

str_replace()

Try it yourself →

Replaces a part with something else.

Syntax

str_replace($old, $new, $text)

Description

Replaces all old parts in the text with the new one.

Example

<?php
echo str_replace("leo", "emma", "leo max leo");

Expected output

emma max emma

When to use?

Text cleaning, filling templates.

substr()

Try it yourself →

Extracts a part of the text.

Syntax

substr($text, $start, $length)

Description

Returns a substring starting from baslangic (with optional length). Negative baslangic counts from the end.

Example

<?php
echo substr("HexLibrary", 0, 3);

Expected output

Hex

When to use?

First N characters, truncation.

explode() / implode()

Try it yourself →

Splits text into an array / joins an array into text.

Syntax

explode($separator, $text) · implode($separator, $arr)

Description

explode splits text into parts (arr); implode does the reverse (text).

Example

<?php
$parts = explode(",", "a,b,c");
echo implode("-", $parts);

Expected output

a-b-c

When to use?

CSV parsing, arr→text conversion.

strpos()

Try it yourself →

Finds the position of a substring.

Syntax

strpos($text, $part)

Description

Returns the starting position of the part (from 0); returns false if not found.

Example

<?php
echo strpos("hello", "ll");

Expected output

2

When to use?

Searching, checking if a word exists.

Common mistakes

  • ⚠️ Don't confuse position 0 with false; check with === (if (strpos(...) !== false)).
HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code