I think preg_match is a bit overkill for searching a specific string. It’s just an opinion of course. You could find it in the following manner. Perhaps we could test it to see.
[php]
$urls = [
‘exampleexample.com’,
‘example.com’,
];
$input = ‘example.com/category/topic/story.html’;
$testing = array_search($input,$urls);
if($testing !== false) {
echo $testing . ’ was found!’;
} else {
echo $input . ’ does not exist.’;
}
[/php]
So, I went ahead and tested it. This was the results.
Array
(
[0] => Array
(
[Number_of_Loops_to_Perform_Test] => 10,000
[Number_of_Tests_Performed] => 2
[Start_of_Test] => 04-18-2016 05:32:13pm
)
[Test: 1] => Array
(
[Code:] =>
$urls = [
'exampleexample.com',
'example.com',
];
$input = 'example.com/category/topic/story.html';
foreach ( $urls as $url ){
if ( preg_match("/$url/", $input)){
$store = "<p>Found {$url} in {$input}</p>";
} else {
$store = "<p>Could not find {$url} in {$input}</p>";
}
}
[Start] => 1461015133.914
[End] => 1461015133.9573
[Elapsed] => 0.04325
)
[Test: 2] => Array
(
[Code:] =>
$urls = [
'exampleexample.com',
'example.com',
];
$input = 'example.com/category/topic/story.html';
$testing = array_search($input,$urls);
if($testing !== false) {
$store = $testing . ' was found!';
} else {
$store = $input . ' does not exist.';
}
[Start] => 1461015133.9576
[End] => 1461015133.9664
[Elapsed] => 0.00885
)
)