Possible Duplicate:
how can i solve “ Deprecated: Function eregi() is deprecated” error
Converting ereg expressions to preg置换弃用eregi
我想简单地输出文件夹中的所有图像阵列我的服务器上。不幸的是,我对php知之甚少。我收到了eregi弃用的错误,我不知道如何解决这个问题。我尝试了preg_match和stripos,可能不正确,但无济于事。帮帮我!
<?
//PHP SCRIPT: getimages.php
Header("content-type: application/x-javascript");
//This function gets the file names of all images in the current directory
//and ouputs them as a JavaScript array
function returnimages($dirname=".") {
$pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)"; //valid image extensions
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){ //if this file is a valid image
//Output it as a JavaScript array element
echo 'smootharray['.$curimage.']="'.$file .'";';
$curimage++;
}
}
closedir($handle);
}
return($files);
}
echo 'var smootharray=new Array();'; //Define array in JavaScript
returnimages() //Output the array elements containing the image file names
?>
另外,我在WordPress调用这个就好像它是一个脚本,像这样:
<script type='text/javascript' src='http://www.foxterrier.com/wp-content/themes/shape/smooths/getimages.php?ver=3.3.1'></script>
然后我使用了一个数组和jQuery的周期插件另一个脚本。它似乎在我的旧服务器上工作,但现在不在新服务器上(可能是由于eregi错误)。这种编码是否有问题,如果是的话,有什么更好的?谢谢!
谢谢凯莉,但我已经看了很多过时eregi线程,我似乎无法弄清楚。 – Zade 2012-03-24 01:27:04