Preg_match for pattern matching
📖 Scenario: You are building a simple PHP script to check if a user's input contains a specific word. This is useful for filtering or validating text inputs in web forms.
🎯 Goal: Build a PHP script that uses preg_match to find if the word "hello" appears in a given string.
📋 What You'll Learn
Create a variable called
text with the exact string "Say hello to the world".Create a variable called
pattern with the exact regex pattern "/hello/".Use
preg_match with $pattern and $text to check for a match and store the result in $matchFound.Print
"Match found!" if $matchFound is true, otherwise print "No match found.".💡 Why This Matters
🌍 Real World
Pattern matching is used in web forms to validate user input, like checking if an email or phone number is correct.
💼 Career
Knowing how to use <code>preg_match</code> helps in backend web development and data validation tasks.
Progress0 / 4 steps