What is the difference between strpos() and stripos()? strpos() और stripos() में क्या अंतर है?
Both find the position of the first occurrence of a substring within a string. The only difference is case sensitivity.
| Function | Case sensitive? |
|---|---|
| strpos() | Yes |
| stripos() | No (case-insensitive) |
strpos('Hello World', 'world'); // false, case mismatch
stripos('Hello World', 'world'); // 6, found ignoring caseInterview tip: Warn about the classic bug: strpos() can return 0 (a valid position) which is falsy in loose comparisons. Always check with === false instead of if (!strpos(...)) to correctly detect 'not found'.
if (strpos($str, 'needle') === false) {
echo 'Not found';
}दोनों string में substring की पहली occurrence की position ढूंढते हैं। इनमें सिर्फ case sensitivity का अंतर है।
| Function | Case sensitive? |
|---|---|
| strpos() | हाँ |
| stripos() | नहीं (case-insensitive) |
strpos('Hello World', 'world'); // false, case mismatch
stripos('Hello World', 'world'); // 6, case ignore करके मिलाइंटरव्यू टिप: क्लासिक बग की चेतावनी दें: strpos() 0 रिटर्न कर सकता है (एक valid position) जो loose comparison में falsy है। 'not found' सही detect करने के लिए हमेशा === false इस्तेमाल करें, if (!strpos(...)) नहीं।
if (strpos($str, 'needle') === false) {
echo 'Not found';
}Was this answer clear?