Practice Questions for PHP Strings

🟢 Level 1: Basic (Easy)

1️⃣ Create a string "Hello PHP" and print it.

2️⃣ Find the length of a string "Programming".

3️⃣ Convert "hello world" into:

  • Uppercase
  • Capitalized words

4️⃣ Reverse the string "OpenAI".

5️⃣ Check if the word "PHP" exists in "I love PHP programming".


🟡 Level 2: Intermediate

6️⃣ Concatenate two strings:

$first = "Web";
$second = "Development";

7️⃣ Extract "World" from "Hello World" using substr().

8️⃣ Remove extra spaces from:

"   PHP is awesome   "

9️⃣ Replace "Java" with "PHP" in:

"I love Java"

🔟 Count how many times "a" appears in "banana".


🟠 Level 3: Arrays + Strings

1️⃣1️⃣ Convert this string into an array:

"red,green,blue"

1️⃣2️⃣ Convert this array into a string:

["HTML", "CSS", "JS"]

1️⃣3️⃣ Split a sentence into words:

"PHP is easy to learn"

1️⃣4️⃣ Join words with -:

["2026", "03", "30"]

🔵 Level 4: Logic Based

1️⃣5️⃣ Check if a string is Palindrome
Example: "madam"

1️⃣6️⃣ Count total words in a string.

1️⃣7️⃣ Remove all vowels from a string.

1️⃣8️⃣ Find the longest word in a sentence.

1️⃣9️⃣ Convert a string into Title Case without using ucwords().


🔴 Level 5: Regex (Important)

2️⃣0️⃣ Check if a string contains only numbers.

2️⃣1️⃣ Validate an email address.

2️⃣2️⃣ Remove all digits from a string:

"abc123xyz456"

2️⃣3️⃣ Extract all numbers from a string.

2️⃣4️⃣ Check if a password contains:

  • At least 1 number
  • At least 1 uppercase letter

🟣 Level 6: Real-World Problems

2️⃣5️⃣ Create a username generator:

"Aditya Kumar Singh" → aditya_kumar

2️⃣6️⃣ Create a slug generator:

"Learn PHP in 2026!" → learn-php-in-2026

2️⃣7️⃣ Mask an email:

test@gmail.com → t***@gmail.com

2️⃣8️⃣ Count characters, words, vowels in a paragraph.

2️⃣9️⃣ Format currency:

1000000 → 10,00,000

🧠 Bonus Challenge (Advanced)

3️⃣0️⃣ Build a mini search system:

  • Input: keyword
  • Check if it exists in a paragraph
  • Highlight matched word

🚀 Tip for Students

Practice in this order:
👉 Basic → Manipulation → explode/implode → Regex → Real projects