如何使用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) === '-');