fork download
  1. <?php
  2.  
  3. $str = [
  4. 'categories_widget-__i__',
  5. 'categories_widget-10',
  6. 'categories_widget-test-extra-hyphens-...'
  7. ];
  8.  
  9. function stripFn($str){
  10. return substr($str, 0, strrpos($str, '-'));
  11. }
  12.  
  13. echo stripFn($str[0]), PHP_EOL,
  14. stripFn($str[1]), PHP_EOL,
  15. stripFn($str[2]);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
categories_widget
categories_widget
categories_widget-test-extra-hyphens