Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.