stripos

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).

strpos return wrong position at hebrew

半城伤御伤魂 提交于 2020-01-25 04:26:27
问题 I need help... I have hebrew php string and I want search position of substring. my code: $string = "אבגד הוזח טי"; $find = "הוזח"; $pos = strpos($string, $find); echo $pos; The strpos found the substring, but return wrong value of position. It return $pos value 9 Instead of 5. Why the strpos not working in hebrew strings? Can you help me please? 回答1: Try using mb_strpos. You will have to set your internal character encoding to UTF-8 using mb_internal_encoding . mb_internal_encoding("UTF-8");

I need to check if certain number is in string of numbers

可紊 提交于 2019-12-26 02:46:05
问题 I really need some help with this... i just cant make it work. For now i have this piece of code and it's working fine. What it does is... retuns all files within a directory according to date in their name. <?php header('Access-Control-Allow-Origin: *'); $imagesDir = ''; $images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE); $filteredImages = []; foreach($images as $image) { $current_date = date("Ymd"); $file_date = substr($image, 0, 8); if (strcmp($current_date, $file_date)>=0)

which is the fast process strpos()/stripos() or preg_match() in php

﹥>﹥吖頭↗ 提交于 2019-12-18 17:08:42
问题 I just want to known which one will be fast of strpos()/stripos() or preg_match() functions in php. 回答1: I found this blog that has run some testes regarding your question, the result was: strpos() is 3-16 times faster than preg_match() stripos() is 2-30 times slower than strpos() stripos() is 20-100 percent faster than preg_match() with the caseless modifier "//i" using a regular expression in preg_match() is not faster than using a long string using the utf8 modifier "//u" in preg_match()

Request URI - If URL contains X & does Not contain Y - then do something

99封情书 提交于 2019-12-10 12:24:41
问题 Hi there my current code looks like this: if (stripos($_SERVER['REQUEST_URI'],'cake') !== false) {echo '<div class="clear"></div><a href="http://www.example.com/cakes/" class="btn"> >> View all Cakes</a>';} This works well to check if the current URL contains the word 'cake' and Then display a link to all cakes. What I need to add to this is: If URL contains 'cake' but does not contain 'carrot' Then display a link to all cakes. Any ideas on how I can modify? Many Thanks 回答1: You can try the