PHP
June 3, 2026 3 min read

PHP String Functions: Manipulating and Analyzing Text

HS
HEMANT SINGH
Technical Writer & Educator
  1. strlen(string)
  2. Return length of a string
  3. strpos(string, char)
  4. Return position of the first occurrence of a string in another string
  5. str_replace(old_word, new_word, string)
  6. Replace a string with another string in a string
  7. addslashes(str)
  8. Return a string by adding a backslash in front of commas in given string
  9. chr(number)
  10. Return the character of the specified character of ASCII (65)
  11. explode(string)
  12. Break a string into an array
  13. implode(array)
  14. Return a string from elements of an array.
  15. join
  16. Alternative of implode
  17. lcfirst(string)
  18. Convert the first character of a string into lower case
  19. md5(string)
  20. Calculate md5 of a string
  21. nl2br(string)
  22. Insert line break in front of each newline in a string
  23. ltrim (string)
  24. Remove whitespace and other characters from the left side of a string
  25. rtrim(string)
  26. Remove whitespace and other characters from the right side of a string
  27. str_split(string)
  28. Split a string into an array
  29. strip_tags(string)
  30. Strip HTML, PHP tags from a string
  31. substr(string, start, end)
  32. Return a part of a string
  33. ucfirst(string)
  34. Convert the first character into uppercase of a string
  35. ucwords(string)
  36. Convert the first character into uppercase of each word
  37. wordwrap(string, n, "\n\r<br>")
  38. Wrap a string to a given number of characters.

Example

<?php 

echo strlen("web design");
echo "<br>";

echo str_word_count("web design");
echo "<br>";

echo strrev("web design");
echo "<br>";

echo strpos("web design", "design");
echo "<br>";

echo str_replace("design", "development", "web design");
echo "<br>";

echo addslashes("web design's");
echo "<br>";

echo chr(65);
echo "<br>";

print_r( explode(" ", "Web design") );
echo "<br>";

echo implode(" ", ["web", "design"]);
echo "<br>";

echo join(" ",["web", "design"]);
echo "<br>";

echo lcfirst("WEB DESIGN");
echo "<br>";

echo md5("web design");
echo "<br>";

echo nl2br("web design \r\n capscom technology almora");
echo "<br>";

echo ltrim("  web design  ");
echo "<br>";

echo rtrim("  web design  ");
echo "<br>";

print_r(str_split("web design"));
echo "<br>";

echo strip_tags("<h1>web design</h1>");
echo "<br>";

echo substr("web design", 3, 7);
echo "<br>";

echo ucfirst("web design");
echo "<br>";

echo ucwords("web design");
echo "<br>";

echo wordwrap("web design and development", 10, "<br>\n");
echo "<br>";
?>