1

I have below code, which gets me file path as voicetube/record/1985150721112615 but I need only 1985150721112615 exploding first two folders,please help me on this

$sql = "SELECT filePath FROM user_recordings ORDER BY recordDate ASC";
$result = mysql_query($sql);
$var = array();
while ($row = mysql_fetch_array($result)) 
{
    $var[] = $row['filePath'];
}
Jazi
  • 6,569
  • 13
  • 60
  • 92
Sagar H
  • 141
  • 1
  • 10
  • You can just split the string everytime there's a `/` and the question:"How to do that?", is definitely a duplicate – Loko Jul 21 '15 at 11:43

2 Answers2

3

You are looking for basename();

   $var[] = basename($row['filePath']);
donald123
  • 5,638
  • 3
  • 26
  • 23
0

You can use explode function, and grab it's last index.

while ($row = mysql_fetch_array($result)) 
{
    $arr = explode('/', $row['filePath']);
    $var[] = $arr[count($arr) -1];
}
kamal pal
  • 4,187
  • 5
  • 25
  • 40