php preg_match, matching when 2 words might come in random sequence

天涯浪子 提交于 2019-12-02 03:50:25

If you're just testing for the presence of the two words in the string you could use

'/couple.*2 pcs|2 pcs.*couple/' 

use strpos()

if(strpos($string, '2 pcs') !== False){
 //its found
}

or matching at first and at end

if(preg_match("/(^(2 pcs|couples)|(2 pcs|couples)$)/", '2 pcs watch for couples')){
//echo "found";
}

or

Matching anywhere:

if(preg_match("/(2 pcs|couples)/", '2 pcs watch for couples')){
//echo "found";
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!