ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => ข้อความที่เริ่มโดย: Fallen ที่ 11 พฤษภาคม 2017, 09:25:07



หัวข้อ: ลิสชื่อไฟล์ ที่มีคำว่า xx ใน directory เขียนยังไงเหรอครับ
เริ่มหัวข้อโดย: Fallen ที่ 11 พฤษภาคม 2017, 09:25:07
ผมมี 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");
      }
    }
  }

?>


หัวข้อ: Re: ลิสชื่อไฟล์ ที่มีคำว่า xx ใน directory เขียนยังไงเหรอครับ
เริ่มหัวข้อโดย: vii ที่ 12 พฤษภาคม 2017, 11:01:27
โค๊ด:
if (stripos($file, 'xx') !== false) {
    // มี xx
}


หัวข้อ: Re: ลิสชื่อไฟล์ ที่มีคำว่า xx ใน directory เขียนยังไงเหรอครับ
เริ่มหัวข้อโดย: Fallen ที่ 12 พฤษภาคม 2017, 11:19:46
โค๊ด:
if (stripos($file, 'xx') !== false) {
    // มี xx
}

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

(โค๊ดข้างบน อนุญาตให้ใฟ้แสดงไฟล์สกุล .jpg,jpeg แสดงได้)


หัวข้อ: Re: ลิสชื่อไฟล์ ที่มีคำว่า xx ใน directory เขียนยังไงเหรอครับ
เริ่มหัวข้อโดย: 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");
        }
      }
    }
  }

?>



หัวข้อ: Re: ลิสชื่อไฟล์ ที่มีคำว่า xx ใน directory เขียนยังไงเหรอครับ
เริ่มหัวข้อโดย: Fallen ที่ 12 พฤษภาคม 2017, 16:14:32
โค๊ด:
<?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: