我有變量x,我想看看它是否包含像hs
這樣的字符串,即使值可能是cug hs ib ap
。有人能幫我弄清楚這個嗎?謝謝!PHP檢查字符串中的字符串
0
A
回答
1
1
if(strpos($big_string, $sub_string) !== false)
{
// $big_string contains $sub_string
}
1
你可以使用strpos
if (strpos($haystack, $needle) !== false) {
echo "the string '{$needle}' was found within '{$haystack}'";
}
1
你可以使用substr_count
.. http://php.net/substr_count或strpos
,http://php.net/strpos
1
要麼strpos()或stripos函數()(具體取決於您是否有興趣區分大小寫)。
相關問題
- 1. 檢查字符串的子字符串
- 2. PHP檢查空字符串
- 3. 檢查字符串中的字符
- 4. 檢查字符串
- 5. 檢查字符串
- 6. 檢查字符串
- 7. 檢查字符串
- 8. 想法檢查字符串的某些字符的字符串檢查器?
- 9. 字母字符檢查字符串
- 10. 在PHP中檢查字符串長度
- 11. 查找字符串中的字符串
- 12. 檢查某些字符的字符串
- 13. 檢查字符串包含的字符
- 14. 檢查字符串中
- 15. 檢查字符串中的字符串在javascript中
- 16. 檢查PHP字符串中的無效字符
- 17. PHP的檢查如果字符串中國字符
- 18. 如何檢查字符串中的波斯字符由php
- 19. Python:字符串中的字符串檢查失敗
- 20. 包含在字符串列表中的檢查字符串
- 21. XML解析:檢查字符串C++中的字符串
- 22. 檢查字符串數組中的字符串C
- 23. 的JavaScript - 檢查字符串
- 24. 在字符串中查找字符串
- 25. 爲字符循環檢查字符串
- 26. 檢查字符串包含Unicode字符
- 27. PHP字符的字符串
- 28. C - 檢查字符串是否是另一個字符串的子字符串
- 29. PHP - 字符串的子字符串
- 30. 查找字符串中的字PHP
是什麼+的strstr之間strpos的區別? – 2011-12-16 22:46:40
strstr返回從第一次出現開始的字符串,而strpos返回子串的數字(位置) – SlavaNov 2011-12-16 22:48:22
@JosephTorraca:`strstr`查找字符串中第一次出現子字符串,從該索引返回字符串,除非第三個參數是設置爲「true」。 `strpos`返回第一次出現子字符串的第一個字符的索引,如果沒有找到則返回false。 – 2011-12-16 22:49:56