ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingลิสชื่อไฟล์ ที่มีคำว่า xx ใน directory เขียนยังไงเหรอครับ
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: ลิสชื่อไฟล์ ที่มีคำว่า xx ใน directory เขียนยังไงเหรอครับ  (อ่าน 507 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
Fallen
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 162
ออฟไลน์ ออฟไลน์

กระทู้: 2,751



ดูรายละเอียด เว็บไซต์
« เมื่อ: 11 พฤษภาคม 2017, 09:25:07 »

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

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");
      }
    }
  }

?>
บันทึกการเข้า

vii
Verified Seller
สมุนแก๊งเสียว
*

พลังน้ำใจ: 132
ออฟไลน์ ออฟไลน์

กระทู้: 944



ดูรายละเอียด เว็บไซต์
« ตอบ #1 เมื่อ: 12 พฤษภาคม 2017, 11:01:27 »

โค๊ด:
if (stripos($file, 'xx') !== false) {
    // มี xx
}
บันทึกการเข้า

Fallen
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 162
ออฟไลน์ ออฟไลน์

กระทู้: 2,751



ดูรายละเอียด เว็บไซต์
« ตอบ #2 เมื่อ: 12 พฤษภาคม 2017, 11:19:46 »

โค๊ด:
if (stripos($file, 'xx') !== false) {
    // มี xx
}

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

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

thenesta
Newbie
*

พลังน้ำใจ: 5
ออฟไลน์ ออฟไลน์

กระทู้: 25



ดูรายละเอียด
« ตอบ #3 เมื่อ: 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");
        }
      }
    }
  }

?>

บันทึกการเข้า
Fallen
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 162
ออฟไลน์ ออฟไลน์

กระทู้: 2,751



ดูรายละเอียด เว็บไซต์
« ตอบ #4 เมื่อ: 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
บันทึกการเข้า

หน้า: [1]   ขึ้นบน
พิมพ์