strpos

PHP's strpos() not working and always getting into the if condition

試著忘記壹切 提交于 2021-01-28 05:06:43
问题 I'm trying to check if a specific character is not present in a string in my code and apparently php doesn't care about anything and always gets inside the if foreach($inserted as $letter) { if(strpos($word, $letter) !== true) //if $letter not in $word { echo "$word , $letter, "; $lives--; } } In this case $word is "abc" and $letter is "b", I've tried changing a lot of random things like from true to false and things like that but I can't get it, can anyone help me please? 回答1: Changing the

PHP's strpos() not working and always getting into the if condition

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-28 05:04:19
问题 I'm trying to check if a specific character is not present in a string in my code and apparently php doesn't care about anything and always gets inside the if foreach($inserted as $letter) { if(strpos($word, $letter) !== true) //if $letter not in $word { echo "$word , $letter, "; $lives--; } } In this case $word is "abc" and $letter is "b", I've tried changing a lot of random things like from true to false and things like that but I can't get it, can anyone help me please? 回答1: Changing the

why is a strpos that is !== false not true?

走远了吗. 提交于 2020-08-07 07:49:56
问题 Consider the following example: $a='This is a test'; If I now do: if(strpos($a,'is a') !== false) { echo 'True'; } It get: True However, if I use if(strpos($a,'is a') === true) { echo 'True'; } I get nothing. Why is !==false not ===true in this context I checked the PHP docs on strpos() but did not find any explanation on this. 回答1: Because strpos() never returns true: Returns the position of where the needle exists relative to the beginning of the haystack string (independent of offset).

If condition not working with strpos

大兔子大兔子 提交于 2020-06-29 11:52:06
问题 I created custom function OutputMessage from where i'm inserting error message with its ClassStyle like this Error: image upload failed! and then i'm exploding string and split class from it add in to div class but my function is not working fine. function OutputMessage($Message=''){ if($Message){ $Postion = strpos($Message,":"); if($Postion !== TRUE){ return sprintf('<div class="alert alert-default">%s</div>',$Message); }else{ $Message = explode(": ",$Message); return sprintf('<div class=

判断是手机端还是电脑端 isMobile()

六月ゝ 毕业季﹏ 提交于 2020-03-26 12:03:27
1.在PublicController控制器中写好判断手机端方法。 <?php namespace Home\Controller; use Think\Controller; class PublicController extends Controller { //判断是否是手机端还是电脑端 function isMobile(){ // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])){ return true; } // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息 if (isset ($_SERVER['HTTP_VIA'])){ // 找不到为flase,否则为true return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false; } // 脑残法,判断手机发送的客户端标志,兼容性有待提高 if (isset ($_SERVER['HTTP_USER_AGENT'])){ $clientkeywords = array ('nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-',