There are lines:

/download/doc/bd2/bd217ce34263e9bf8679562067758196.xls|/download/doc/17f/17fc9e435a3d3a1d1e6f12c13fe1262f.xls|/download/doc/42b/42be09853a529555d6f2316f1f29b593.xls 

It is necessary that it turned out:

 bd217ce34263e9bf8679562067758196.xls|17fc9e435a3d3a1d1e6f12c13fe1262f.xls|42be09853a529555d6f2316f1f29b593.xls 

The str_replace function str_replace not work, because after 3 slashes, the parameters change all the time.

Tried the strrchr function

 $param = "/download/doc/bd2/bd217ce34263e9bf8679562067758196.xls|/download/doc/17f/17fc9e435a3d3a1d1e6f12c13fe1262f.xls|/download/doc/42b/42be09853a529555d6f2316f1f29b593.xls "; $string = substr(strrchr($param, "/"), 1); echo $string; 

But she only returns 42be09853a529555d6f2316f1f29b593.xls

  • Split string by '|' and use pathinfo . - Yaant

1 answer 1

For example, so

 $result = preg_replace('~/[\w/]*/~', "", $str); 

either so

 $result = []; foreach(explode('|', $str) as $file){ $result[] = basename($file); } $str = implode("|", $result); 

what can be written as

 $str = implode("|", array_map('basename', explode("|", $str))); 
  • @ YulyaFrolova is suitable, while in the cut out path there are only letters, numbers and / . You may have to extend the set [\w/] other characters. And the question of efficiency on the input line of great length. - teran
  • one
    @ YulyaFrolova, if teran has answered your question, check the box to the left of the answer to mark it as correct - svolex