Jump to content

[SOLVED] using array in strpos()


the_oliver

Recommended Posts

Hello,

 

Im trying to search for a charictor in a string using the following.

 

	$arr = array("\"","<",">");
if (strpos($field, $arr) === false) {
      }

 

if i specify a charictor instaead of using $arr it works fine, however if i use and array ($arr) it won't work. 

I need to search for more then one charictor!

 

Can anyone tell me a good way round this?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/57083-solved-using-array-in-strpos/
Share on other sites

You could create your own little function to handle it.

 

<?php
function my_strpos($haystack, $needle) {
     if (is_array($needle)) {
         foreach ($needle as $need) {
               if (strpos($haystack, $need) !== false) {
                       return true;
               }
         }
     }else {
          if (strpos($haystack, $need) !== false) {
                       return true;
          }
     }

     return false;
}
?>

 

 

http://www.php.net/strpos

Description

int strpos ( string $haystack, mixed $needle [, int $offset] )

 

needle

 

    If needle is not a string, it is converted to an integer and applied as the ordinal value of a character

 

It does not accept an array as the needle. An int or a string.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.