如何根据文件名前面的字母显示按钮?

我创建了按钮以根据文件前面的字母表显示按钮。任何人都可以指导我如何根据文件前面的第一个字母显示按钮。对于我的文件,我的文件名第一个字母是 m。如果文件名第一个字母是 m,我只想显示Edit Meeting File按钮,如果字母不是 m,则不显示Edit Meeting File按钮。下面是我的代码:


<?php

$i = 1;

$files = scandir("upload_dms_file/uploads_filing_file");

$date = $files[$a];

for ($a = 2; $a < count($files); $a++) {


    ?>


    <tr>

        <td> <?php echo $i++; ?></td>

        <td> <a href="upload_dms_file/uploads_filing_file/<?php echo $files[$a]; ?>" target="_blank"> <?php echo $files[$a]; ?></a></td>

        <td>

            <button class="btn btn-sm btn-primary"><a href="upload_dms_file/uploads_filing_file/<?php echo $files[$a]; ?>"

                                                      download="<?php echo $files[$a]; ?>" style="color: white;">

                    Download</a></button>

            &nbsp &nbsp

            <button class="btn btn-sm btn-primary"><a

                        href="upload_dms_file/delete_filing_storage.php?name=uploads_filing_file/<?php echo $files[$a]; ?>" style="color: white;">

                    Delete

                </a></button>


                <button class="btn btn-sm btn-primary"><a

                        href="upload_dms_file/edit_filing_storage.php?name=uploads_filing_file/<?php echo $files[$a]; ?>" style="color: white;">

                    Edit Meeting File 

                </a></button>


        </td>

    </tr>


    <?php

} ?>


这是我的输出页面,此输出显示所有 Edit Meeting File按钮:

http://img3.mukewang.com/638ab5c600016e2c11380291.jpg

希望任何人都可以指导我如何解决它。谢谢。



温温酱
浏览 138回答 2
2回答

慕婉清6462132

只需将输出该按钮的代码包装在一个if块中,该块检查文件名的第一个字母是否为m:<?phpif ($files[$a][0] == 'm') {?><button class="btn btn-sm btn-primary"><a&nbsp; &nbsp; &nbsp; &nbsp; href="upload_dms_file/delete_filing_storage.php?name=uploads_filing_file/<?php echo $files[$a]; ?>" style="color: white;">&nbsp; &nbsp; Edit Meeting File&nbsp;</a></button><?php&nbsp;}?>

烙印99

您需要if在按钮部分添加一个子句:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <button class="btn btn-sm btn-primary"><a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; href="upload_dms_file/delete_filing_storage.php?name=uploads_filing_file/<?php echo $files[$a]; ?>" style="color: white;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Edit Meeting File&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </a></button>应该&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php if(strlen($files[$a]) > 1 and substr($files[$a], 0, 2) = "m-"){ ?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <button class="btn btn-sm btn-primary"><a&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; href="upload_dms_file/delete_filing_storage.php?name=uploads_filing_file/<?php echo $files[$a]; ?>" style="color: white;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Edit Meeting File&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </a></button>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php } ?>
打开App,查看更多内容
随时随地看视频慕课网APP