Reputation: 344
I just want to ask how to find some text in a string. I know that I will gonna use preg_match
function in PHP but I don't know how to use it. Let's say I want to make a web hosting. Shall I do like this:
<?php
$web_hosting_service="hostingservice.com";
$subdomain_name = "subdomain.hostingservice.com";
if(preg_match($web_hosting_service, $subdomain_service) {
echo 'true';
} else {
echo 'false';
}
If not, what I need to do
Upvotes: 0
Views: 29
Reputation: 6446
For simple string-within-a-string checking, use strstr
instead of preg_match
. It's much simpler:
<?php
$web_hosting_service="hostingservice.com";
$subdomain_name = "subdomain.hostingservice.com";
if(strstr($subdomain_name, $web_hosting_service)) {
echo 'true';
}
Upvotes: 1