Jump to content


Photo

Warning: preg_match() expects...


  • Please log in to reply
3 replies to this topic

#1 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 03 July 2006 - 07:22 PM

Warning: preg_match() expects parameter 2 to be string, array given

Hello, the above is the error I am receiving, this is the function...

function audio_files($filelist)
{
   $clean_files = array();
   $extensions = array('\.mp3', '\.aiff', '\.wav', '\.mid'); //add audio extensions
   $read_extensions = '(' . implode('|', $extensions) . ')';

   if(preg_match("#$read_extensions$#", $filelist))
   {
      $clean_files[] = $filelist;
   }
   return $clean_files;
} 

Note, $filelist contains ftp_nlist(). Now, I'm guessing this could be a problem with my web host, so I'll go 'head and post that to.

cPanel 10.8.1-STABLE_31 (PRO 1.0 (RC2))
Apache Core 1.3.34
SpamAssasin 3.1
phpMyAdmin 2.6.1-rc1
PHP 4.4.1 AND 5.0.5
PERL 5.8.6
MySQL 4.1.13-standard-log

Processor Name: 	Intel(R) Celeron(TM) CPU 2.40GHz
Processor speed: 	2394.027 MHz
Processor cache size: 	128 KB
Operating System: 	RedHat Enterprise 3
Memory Information: 	ECC Registered 1024 MB RAM

If anyone could resolve the preg_match() error I am having, please do so...help is appreciated.

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 03 July 2006 - 07:31 PM

Warning: preg_match() expects parameter 2 to be string, array given

That says it all; change your code to loop through the array.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 03 July 2006 - 08:02 PM

Ah.

Well, being slightly new to PHP, would I use a foreach loop to do so? 

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 03 July 2006 - 08:19 PM

Yes. Assuming $filelist will always be an array:

foreach ($filelist as $file) {
  // Each iteration will have a new file in $file until the array runs out.
}

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users