Skip to content
FullStackDost Logo
  • All Courses
  • Blogs
  • Login
  • Register
  • All Courses
  • Blogs
  • Login
  • Register
  • Home
  • All Courses
  • Full Stack Development
  • PHP Tutorial

PHP Tutorial

Curriculum

  • 6 Sections
  • 29 Lessons
  • 3 Weeks
Expand all sectionsCollapse all sections
  • PHP Tutorials
    PHP (Hypertext Preprocessor) is a widely-used open-source scripting language primarily designed for web development.
    3
    • 1.1
      PHP Introduction
      20 Minutes
    • 1.2
      PHP Installation
      15 Minutes
    • 1.5
      PHP Syntax
      35 Minutes
  • PHP Basics
    PHP Basics Unleashed: Dive into the Fundamentals of Web Development!
    10
    • 2.0
      PHP Variables
      30 Minutes
    • 2.1
      PHP Arrays
      35 Minutes
    • 2.2
      PHP Conditions
      40 Minutes
    • 2.3
      PHP Loops
      45 Minutes
    • 2.4
      PHP Functions
      40 Minutes
    • 2.5
      PHP Array Functions
      20 Minutes
    • 2.6
      PHP String Functions
      35 Minutes
    • 2.7
      PHP Superglobals
      25 Minutes
    • 2.8
      PHP GET & POST
      30 Minutes
    • 2.9
      PHP Cookies
      45 Minutes
  • PHP Forms
    Streamline Your Web Forms: Master PHP Form Handling for Seamless User Interactions!
    3
    • 3.0
      PHP Forms
    • 3.1
      PHP Form Validation
      35 Minutes
    • 3.2
      PHP Form essentials
      20 Minutes
  • PHP Advance Topics
    Advanced topics in PHP cover a range of more complex concepts and techniques that are useful for experienced developers looking to build sophisticated web applications.
    8
    • 4.0
      PHP Date and Time
      35 Minutes
    • 4.1
      PHP File Handling
      45 Minutes
    • 4.2
      PHP Sessions
      35 Minutes
    • 4.3
      PHP Filters
      35 Minutes
    • 4.4
      PHP OOPS
      60 Minutes
    • 4.5
      PHP Traits
      45 Minutes
    • 4.6
      PHP Interface
      40 Minutes
    • 4.7
      PHP File upload
      45 Minutes
  • PHP Security
    Fortify Your PHP Skills: Learn Essential Security Practices to Safeguard Your Web Applications!
    1
    • 5.0
      Securing PHP application
  • Discussions on PHP
    Unlock the Power of PHP: Balancing Conciseness and Clarity for Readable Code Mastery
    4
    • 6.0
      Advantages of PHP
    • 6.1
      Disadvantages of PHP
    • 6.2
      Performance of PHP
    • 6.3
      Comparison with Node/JavaScript

PHP String Functions

In PHP, strings are sequences of characters, such as letters, numbers, and symbols, enclosed within single quotes (”) or double quotes (“”). PHP provides a variety of string functions to manipulate and work with strings effectively. Here’s an overview of PHP strings and some commonly used string functions:

1. Declaring Strings:

$var1 = 123;
$string1 = 'Single quoted string $var1';
echo $string1; // output: Single quoted string $var1
$string2 = "Double quoted string $var1";
echo $string2 // output: Double quoted string 123

2. Concatenation:

Concatenation is the process of combining two or more strings into one.

$name = "John";
$greeting = "Hello, " . $name . "!"; // Output: Hello, John!

3. String Length:

Returns the length of a string.

$string = "Hello, World!";
$length = strlen($string); // Output: 13

4. Substring:

Returns a part of a string.

$string = "Hello, World!";
$substring = substr($string, 7); // Output: World!

5. String Replace:

Replaces all occurrences of a search string with a replacement string.

$string = "Hello, World!";
$newString = str_replace("World", "PHP", $string); // Output: Hello, PHP!

6. String to Lowercase/ Uppercase:

Converts a string to lowercase/uppercase.

$string = "Hello, World!";
$lowercase = strtolower($string); // Output: hello, world!
$uppercase = strtoupper($string); // Output: HELLO, WORLD!

7. Trimming:

Removes whitespace or other predefined characters from the beginning and end of a string.

$string = " Hello, World! ";
$trimmed = trim($string); // Output: Hello, World!

8. String Splitting:

Splits a string into an array of substrings based on a delimiter.

$string = "apple,banana,orange";
$fruits = explode(",", $string);
// Output: Array ( [0] => apple [1] => banana [2] => orange )

9. String Comparison:

Compares two strings. Returns 0 if the strings are equal, a negative value if the first string is less than the second, and a positive value if the first string is greater than the second.

$string1 = "apple";
$string2 = "banana";
$result = strcmp($string1, $string2); // Output: A negative value

10. String Searching:

Searches for a substring within a string. Returns the position of the first occurrence if found, or false otherwise.

$string = "Hello, World!";
$position = strpos($string, "World"); // Output: 7

11. String Formatting:

Formats a string using placeholders.

  • $name = "John";
    $age = 30;
    $message = sprintf("My name is %s and I am %d years old.", $name, $age); // Output: My name is John and I am 30 years old.

These are just a few examples of the many string functions available in PHP. String manipulation is a common task in PHP programming, and mastering these functions will enable you to work with strings effectively and efficiently in your applications.

PHP Array Functions
Prev
PHP Superglobals
Next

Copyright © 2025 FullStackDost. All Rights Reserved.

Theme by ILOVEWP