我有这个字符串:

$mystring = "SIZE,DETAIL";

我正在使用:
@if (strpos($mystring, 'SIZE'))
        {{ $item->size }}
@endif
@if (strpos($mystring, 'DETAIL'))
        {{ $item->detail }}
@endif

但这适用于 SIZE,但不适用于 DETAIL。

这里有什么问题?

最佳答案

此函数可能返回 bool 值 FALSE,但也可能返回计算结果为 FALSE 的非 bool 值。

试试这个:

@if (strpos($mystring, 'SIZE') !== false)
    {{ $item->size }}
@endif
@if (strpos($mystring, 'DETAIL') !== false)
    {{ $item->detail }}
@endif

引用:http://php.net/manual/en/function.strpos.php

关于php - 检查字符串是否包含任何文本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41694511/

10-14 15:23
查看更多