Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP脚本在任何DOM中只搜索输出“-”?_Php_Css_Dom_Output - Fatal编程技术网

如何使用PHP脚本在任何DOM中只搜索输出“-”?

如何使用PHP脚本在任何DOM中只搜索输出“-”?,php,css,dom,output,Php,Css,Dom,Output,如何仅搜索输出-(如果有以下DOM) - - 等等 目前,我仅使用以下代码查找此输出-: $input = `<p>-</p>`; if($input == `<p>-</p>`): return true; else: return false; endif; $input=`-`; 如果($input==`-`): 返回true; 其他: 返回false; endif; 有更好的主意吗?试试看 $input = `<p&g

如何仅搜索输出
-
(如果有以下DOM)

  • -

  • -

  • 等等
  • 目前,我仅使用以下代码查找此输出
    -

    $input = `<p>-</p>`;
    if($input == `<p>-</p>`):
       return true;
    else:
       return false;
    endif;
    
    $input=`-

    `; 如果($input==`-

    `): 返回true; 其他: 返回false; endif;
    有更好的主意吗?

    试试看

    $input = `<p>-</p>`;
    $input = `<p><span style="font-size: medium;">-</span></p>`;
    $input = `<p><div>-</div>`;
    if(strpos($input, '>-<')):
       return true;
    else:
       return false;
    endif;
    
    $input=`-

    `; $input=`-

    `; $input=`-`;
    如果(strpos($input,'>-接受的答案不适用于特殊情况,例如标记属性值包含
    >,因为它是完全匹配的,您的尝试已经足够了。如果匹配基于模式,那么您将需要正则表达式。您可以向我展示详细信息吗?哦,除了使用正则表达式之外,您还可以使用
    strpos($dom,'-)
    应该注意的是
    p
    元素不能有
    div
    子元素。@Imran在建议修改时,请理解您需要尝试解决帖子的所有问题,而不仅仅是将
    bootstrap
    更改为
    twitter bootstrap
    ,并知道bootstrap不属于twitter因此,当更改标记有效时,无需在文本中将引导更改为twitter引导。@ImranHamzah可以是if(strpos($input,“>)-这一个,,,如您所述-适用于所有条件。
    $input = '<span title="A valid title >-<">Should NOT match</span>';
    $input = '<span>Should match</span>-';
    
    return (strip_tags($input) === '-');