如何检查字符串是否包含2个子串

时间:2017-05-12 13:29:01

标签: php string boolean substring

$(".appendTree").jstree('create_node', CurrentNode, html, 'last');

对于所有这些变体,我需要返回true,因此/ *和* /存在于字符串中。

尝试

$string = "/*123123123*/";
$string = "123/*123123*/";
$string = "/*123123*/123";
$string = "123/*123123*/123";

但它没有成功:c

2 个答案:

答案 0 :(得分:0)

使用substr_count():http://php.net/manual/en/function.substr-count.php

  

int substr_count(string $ haystack,string $ needle [,int $ offset = 0 [,int $ length]])

答案 1 :(得分:0)

您可以使用:

if (preg_match('%/\*.+\*/%', $string)) {
    $flag = true;
} else {
    $flag = false;
}

Regex Demo and Explanation

相关问题