-2

my string: 1660807356design-1.pdf

I want remove text after dot (if file pdf => remove .pdf)...

I try trim(), replace(), substr() but not working

$file = substr($items['pdf_name'], 0, -4);
Gedeon Mutshipayi
  • 2,871
  • 3
  • 21
  • 42
  • Please DEFINE **not working** and then check this : [sandbox](https://onlinephp.io?s=s7EvyCjg5eLlUkm0VTI0MzOwMDA3NjVLSS3OTM_TNdQrSElTsgbKpmXmpCrYKhSXJhWXFGmoJOooGOgo6JpoWoP0piZn5CuAlYC59nYA&v=8.1.9) – Ken Lee Aug 18 '22 at 07:41
  • A good answer provided here: https://stackoverflow.com/questions/1818310/regular-expression-to-remove-a-files-extension – alexfar Aug 18 '22 at 07:42
  • What if you have `something.nothing.interesting.pdf` as the file name? – nice_dev Aug 18 '22 at 07:49
  • Use [`this`](https://stackoverflow.com/a/22537165/4964822) answer in the marked dupe as it seems to work [`just fine`](https://onlinephp.io/c/8b590) – nice_dev Aug 18 '22 at 07:53

1 Answers1

-1

Try this code

$str = "1660807356design-1.pdf";
echo explode(".",$str)[0];
Kamandlou
  • 44
  • 6