ลิสชื่อไฟล์ ที่มีคำว่า xx ใน directory เขียนยังไงเหรอครับ

เริ่มโดย Fallen, 11 พฤษภาคม 2017, 09:25:07

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

Fallen

ผมมี script ลิส นามสกุลไฟล์ แล้วโชว์ขึ้นมา
ทีนี้ถ้าจะใส่เงื่อนไข ให้ลิส ชื่อไฟล์ที่มีคำว่า xx อยู่ จะใส่คำสั่งอะไร ตรงไหนเหรอครับ  :P
เช่น

xx123.jpg
xx345.jpg



<?php

  
// These files will be ignored
  
$excludedFiles = array (
    
'excludeMe.file',
    
'excludeMeAs.well'
  
);

  
// These file extensions will be ignored
  
$excludedExtensions = array (
    
'jpeg',
    
'่jpg',
  );

  
// Make sure we ignore . and ..
  
$excludedFiles = array_merge($excludedFiles,array('.','..')); 

  
// Loop through directory
  
$count = 0;
  if (
$handle = opendir('.')) {
    while (
false !== ($file = readdir($handle))) {
      
$extn = explode('.',$file);
      
$extn = array_pop($extn);
      
// Only echo links for files that don't match our rules
      
if (!in_array(strtolower($file),$excludedFiles) && !in_array(strtolower($extn),$excludedExtensions)) {
        
$count++;
        print(
"<a href=\"".$file."\">".$file."</a><br />\n");
      }
    }
  }

?>

[direct=https://www.cymiz.com/]ประกันภัย[/direct]
[direct=https://www.cymiz.com/promotion/]ประกันรถยนต์ พรบ มอเตอร์ไซต์ ราคาสมาชิก[/direct]
[direct=http://cymiz.com/].[direct=http://vir9.com].[/direct][/direct]

vii


Fallen

อ้างถึงจาก: vii ใน 12 พฤษภาคม 2017, 11:01:27
if (stripos($file, 'xx') !== false) {
    // มี xx
}


เอาไปรวมกับโค๊ดข้างบนอย่างไรเหรอครับ?
:wanwan011:

(โค๊ดข้างบน อนุญาตให้ใฟ้แสดงไฟล์สกุล .jpg,jpeg แสดงได้)
[direct=https://www.cymiz.com/]ประกันภัย[/direct]
[direct=https://www.cymiz.com/promotion/]ประกันรถยนต์ พรบ มอเตอร์ไซต์ ราคาสมาชิก[/direct]
[direct=http://cymiz.com/].[direct=http://vir9.com].[/direct][/direct]

thenesta


<?php

  
// These files will be ignored
  
$excludedFiles = array (
    
'excludeMe.file',
    
'excludeMeAs.well'
  
);

  
// These file extensions will be ignored
  
$excludedExtensions = array (
    
'jpeg',
    
'่jpg',
  );

  
// Make sure we ignore . and ..
  
$excludedFiles = array_merge($excludedFiles,array('.','..')); 

  
// Loop through directory
  
$count = 0;
  if (
$handle = opendir('.')) {
    while (
false !== ($file = readdir($handle))) {
      
$extn = explode('.',$file);
      
$extn = array_pop($extn);
      
// Only echo links for files that don't match our rules
      
if (!in_array(strtolower($file),$excludedFiles) && !in_array(strtolower($extn),$excludedExtensions)) {
        
$count++;
        if(
strpos($file, 'xx') !== false){
          print(
"<a href=\"".$file."\">".$file."</a><br />\n");
        }
      }
    }
  }

?>


Fallen

อ้างถึงจาก: thenesta ใน 12 พฤษภาคม 2017, 16:05:12

<?php

  
// These files will be ignored
  
$excludedFiles = array (
    
'excludeMe.file',
    
'excludeMeAs.well'
  
);

  
// These file extensions will be ignored
  
$excludedExtensions = array (
    
'jpeg',
    
'่jpg',
  );

  
// Make sure we ignore . and ..
  
$excludedFiles = array_merge($excludedFiles,array('.','..')); 

  
// Loop through directory
  
$count = 0;
  if (
$handle = opendir('.')) {
    while (
false !== ($file = readdir($handle))) {
      
$extn = explode('.',$file);
      
$extn = array_pop($extn);
      
// Only echo links for files that don't match our rules
      
if (!in_array(strtolower($file),$excludedFiles) && !in_array(strtolower($extn),$excludedExtensions)) {
        
$count++;
        if(
strpos($file, 'xx') !== false){
          print(
"<a href=\"".$file."\">".$file."</a><br />\n");
        }
      }
    }
  }

?>



โอ้วว ขอบพระคุณครับ ใช้ได้เเล้ว ดีใจมาก
+1
:wanwan017: :wanwan017:
[direct=https://www.cymiz.com/]ประกันภัย[/direct]
[direct=https://www.cymiz.com/promotion/]ประกันรถยนต์ พรบ มอเตอร์ไซต์ ราคาสมาชิก[/direct]
[direct=http://cymiz.com/].[direct=http://vir9.com].[/direct][/direct]