开发者

Search for a semicolon in PHP POST

I would like to know if it is possible to search th开发者_如何学Pythonrough a $_POST variable and if a ";" is found then trigger an if statement.

For example:

if ";" is True{
 XXXXXX
} 


Sure, use strpos to check if the character is found in your string.

<?php

if(strpos($_POST['yourkey'],';')!==false){
    //if it gets here, a ; was found
    }

You have to use a strict check (=== or !==) for the position returned. Otherwise, if strpos returns a 0 because the ; is the first character in the string, it will resolve to boolean false, meaning the result is misinterpreted.


You can tell if a char exists in a string using strpos.

It returns the position of the string.

strpos($haystack, $needle);

Be careful of you result being the first position, i.e. 0. As 0 equates to false in PHP.

In this case use === to test for 0 rather than false.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜