I want to know if a string is in another string at least once.
I want to check if Shadowbox.init
then any (optionnal) combisaison of whitespace then (
is inside $myString at least once.
- Shadowbox.init must be found (case sensitive)
- It can be followed by any number of white spaces (spaces, tabs, newlines...)
- The whitespaces or
init
is then followed by an开发者_JAVA技巧 opening parenthesis(
So far I have:
$matches = preg_match('/Shadowbox.init[\s]*(/', $myString);
Some examples:
/*
Shadowbox.init(); --> OK
Shadowbox.init ( ); --> OK
Shadowbox.init (foo); --> OK
Shadowbox.init ); --> Bad missing (
Shadowbox.init --> Bad missing (
Shadowbox. init(); --> Bad space after dot
*/
You were nearly there:
$matches = preg_match('/Shadowbox\.init\s*\(/', $myString);
You need to escape the parenthesis and the dot. And you don't need to put brackets around \s
.
You don't need regex: http://php.net/manual/en/function.strpos.php
精彩评论