raziqijr Posted August 5, 2012 Share Posted August 5, 2012 this is the the page 405 chapter 13 The foreach loop will access each item in the $very_bad array one at a time, assigning each item to $v. Within the loop, the stripos( ) function will check if the item is in the string provided to this function as $value. The stripos( ) function performs a caseinsensitive search (so it would match bcc:, Bcc:, bCC:, etc.). The function returns a Boolean TRUE if the needle is found in the haystack (e.g., looking for occurrences of $v in $value). The conditional therefore says that if that function’s results do not equal FALSE (i.e., $v was not found in $value), return an empty string. in above page i bold the text which should really have said (i.e $v was found in $value) am i right pls correct me if i am wrong. Link to comment Share on other sites More sharing options...
Larry Posted August 14, 2012 Share Posted August 14, 2012 No, it's correct as written. If the value was not found, in which case the stripos() function returns false, then return an empty string. Link to comment Share on other sites More sharing options...
raziqijr Posted August 19, 2012 Author Share Posted August 19, 2012 No, it's correct as written. If the value was not found, in which case the stripos() function returns false, then return an empty string. look sir if stripos() functions result do not equal to false which mean ($v is found in $value) then return empty string. because if stripos() function result is false then it means ($v is not found in $value ) . i am confused pls give me a simple example Link to comment Share on other sites More sharing options...
HartleySan Posted August 19, 2012 Share Posted August 19, 2012 raziqijr, I don't think anyone understood your response, but to test for false, do the following: if (stripos($value, $v) === false) { return ''; } See the following link for details and more examples: http://php.net/manual/en/function.stripos.php Link to comment Share on other sites More sharing options...
raziqijr Posted August 19, 2012 Author Share Posted August 19, 2012 raziqijr, I don't think anyone understood your response, but to test for false, do the following: if (stripos($value, $v) === false) { return ''; } See the following link for details and more examples: http://php.net/manua...ion.stripos.php raziqijr, I don't think anyone understood your response, but to test for false, do the following: if (stripos($value, $v) === false) { return ''; } See the following link for details and more examples: http://php.net/manua...ion.stripos.php thanks for your assistant , your right i understood your code but could you pls explain this for me foreach ($very_bad as $v) { if (stripos($value, $v) !== false) return ""; } Link to comment Share on other sites More sharing options...
HartleySan Posted August 20, 2012 Share Posted August 20, 2012 !== is the opposite of ===. So if stripos($value, $v) returns anything but false (in other words, the string $v is found in the larger string $value), then the if statement evaluates to true and an empty string is returned. Basically, this code is something that Larry wrote in order to avoid really bad strings in messages input by the user. If any of the strings in the $very_bad array are found in the $value string (which is what the user typed), then an empty string is returned (because the user, either intentionally or unintentionally, typed something that could screw up the system). 1 Link to comment Share on other sites More sharing options...
raziqijr Posted August 22, 2012 Author Share Posted August 22, 2012 !== is the opposite of ===. So if stripos($value, $v) returns anything but false (in other words, the string $v is found in the larger string $value), then the if statement evaluates to true and an empty string is returned. Basically, this code is something that Larry wrote in order to avoid really bad strings in messages input by the user. If any of the strings in the $very_bad array are found in the $value string (which is what the user typed), then an empty string is returned (because the user, either intentionally or unintentionally, typed something that could screw up the system). ok now read it carefully The foreach loop will access each item in the $very_bad array one at a time, assigning each item to $v. Within the loop, the stripos( ) function will check if the item is in the string provided to this function as $value. The stripos( ) function performs a caseinsensitive search (so it would match bcc:, Bcc:, bCC:, etc.). The function returns a Boolean TRUE if the needle is found in the haystack (e.g., looking for occurrences of $v in $value). The conditional therefore says that if that function’s results do not equal FALSE (i.e., $v was not found in $value), return an empty string. the bold red text above should really have said (i.e , $v was found in $value) not (i.e., $v was not found in $value) what do u say? Link to comment Share on other sites More sharing options...
HartleySan Posted August 22, 2012 Share Posted August 22, 2012 Yes, that's exactly what I said in my post. Does Larry's book say "$v was not found in $value"? If so, that's an error and should be noted, you're right. Link to comment Share on other sites More sharing options...
raziqijr Posted August 22, 2012 Author Share Posted August 22, 2012 Yes, that's exactly what I said in my post. Does Larry's book say "$v was not found in $value"? If so, that's an error and should be noted, you're right. yes its written in the book "$v was not found in $value" after all this is what i was talking about Link to comment Share on other sites More sharing options...
HartleySan Posted August 22, 2012 Share Posted August 22, 2012 Well, then that's incorrect. Hopefully Larry will acknowledge that. You may want to check the errata page for the book, as it might have already been acknowledged. Link to comment Share on other sites More sharing options...
raziqijr Posted August 22, 2012 Author Share Posted August 22, 2012 Well, then that's incorrect. Hopefully Larry will acknowledge that. You may want to check the errata page for the book, as it might have already been acknowledged. ok thanks for your time i'll check Link to comment Share on other sites More sharing options...
Recommended Posts