如何在PHP中使用pathinfo? [英] How to use pathinfo in php?

查看:74
本文介绍了如何在PHP中使用pathinfo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理如下所示的php代码,其中Line#A打印以下数组(如下所示的php代码).我的代码似乎不在switch语句内.我不知道为什么.

I am working on a php code as shown below on which Line#A prints the following array (shown below php code). My code doesn't seems to go inside switch statement. I am not sure why.

我在A行添加了 print_r($ parts)以便打印$ parts的值.

I added print_r($parts) at Line A in order to print the value of $parts.

php代码:

<?php
    if (!empty($_POST['id']))
    {
    for($i=0; $i <count($mp4_files); $i++) {
    if($i == $_POST['id']) {
    $f = $mp4_files[$i];
    $parts = pathinfo($f);
    print_r($parts);                    // Line A
    switch ($parts['extension'])
    {
    echo "Hello World";                 // Line B
    case 'mp4' :
    $filePath = $src_dir . DS . $f;
    system('ffmpeg -i ' . $filePath . ' -map 0:2 -ac 1 ' . $destination_dir . DS . $parts['filename'] . '.mp3', $result);
    }
    }
    }
    }
?>

输出(行A):

Array 
(
    [dirname]  => .
    [basename] => hello.mp4
    [extension] => mp4
    [filename] => hello
)

我在B行使用了 echo"Hello World" ,但是由于某些原因,它无法打印并在控制台上抛出 500内部服务器错误.

I have used echo "Hello World" at Line B but for some reasons, its not getting printed and throwing 500 internal server error on console.

问题陈述:

我想知道应该在php代码中进行哪些更改,以使其进入switch语句.

I am wondering what changes I should make in the php code so that it goes inside switch statement.

推荐答案

错误500是由行B上的 echo"Hello World" 引起的,该情况不在大小写 mp4 .

The error 500 is caused by echo "Hello World" at Line B which is outside of case mp4.

您的switch语句应如下所示.

Your switch statement should be like this.

switch ($parts['extension']) {
    case 'mp4':
        echo "hello world";
        $filePath = $src_dir . DS . $f;
        system('ffmpeg -i ' . $filePath . ' -map 0:2 -ac 1 ' . $destination_dir . DS . $parts['filename'] . '.mp3', $result);
        break;
}

这篇关于如何在PHP中使用pathinfo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆