I am working on a php code as shown below in which I am trying to retrieve mp4 and xml files name.
$src_dir = 'incoming_folder'; /* Place where mp4 file is present */
$mp4_files = preg_grep('~\.(mp4)$~', scandir($src_dir)); /* Line #Y */
print_r($mp4_files); /* Line #A */
$xml_files = preg_grep('~\.(xml)$~', scandir($src_dir)); /* Line #Z */
print_r($xml_files); /* Line #B */
Line#A prints the following:
Array ( [2] => 45017P.mp4 [3] => 45031P.mp4 [5] => hello.mp4
Line#B prints the following:
Array ( [2] => 45017.xml [5] => 45031P.xml [7] => hello.xml )
I have integrated Line#Y and Line#Z code in the html below in order to retrieve the file names from a directory.
<table width="100%">
<tr>
<!-- This inline css will go inside addiional css -->
</tr>
<th style="width:8%;">House#</th>
<th style="width:8%;">Date</th>
<th style="width:8%;" >Time</th>
<th style="width:8%;">MP4</th>
<th style="width:8%;" >XML</th>
<?php foreach ($mp4_files as $file ) {
foreach ($xml_files as $file2 ) {
?>
<tr>
<td style="width:8%; text-align:center;"> <?php echo basename($file, ".mp4"); ?></td>
<td style="width:8%; text-align:center;"><?php echo date("F d Y",filemtime("incoming_folder/$file")); ?></td>
<td style="width:8%; text-align:center;"><?php echo date("H:i:s",filemtime("incoming_folder/$file")); ?></td>
<td style="width:8%; text-align:center;"> <?php echo basename($file); ?></td>
<td style="width:8%; text-align:center;"> <?php echo basename($file2); ?></td>
</tr>
<?php
}
}
?>
</table>
The above html/php code prints the following:
House# Date Time MP4 XML
45017P April 30 2019 10:21:12 45017P.mp4 45017P.xml
45017P April 30 2019 10:21:12 45017P.mp4 45031P.xml
45017P April 30 2019 10:21:12 45017P.mp4 hello.xml
45031P May 01 2019 14:56:56 45031P.mp4 45017P.xml
45031P May 01 2019 14:56:56 45031P.mp4 45031P.xml
45031P May 01 2019 14:56:56 45031P.mp4 hello.xml
hello April 30 2019 10:21:12 hello.mp4 45017P.xml
hello April 30 2019 10:21:12 hello.mp4 45031P.xml
hello April 30 2019 10:21:12 hello.mp4 hello.xml
Problem Statement:
In the o/p above for the column House#, I can see two 45017P
, two 45031P
, and two hello
. I am wondering how I can avoid the redundancy so that it shows something like this:
House# Date Time MP4 XML
45017P April 30 2019 10:21:12 45017P.mp4 45017P.xml
45031P May 01 2019 14:56:56 45031P.mp4 45031P.xml
hello April 30 2019 10:21:12 hello.mp4 hello.xml