Suppose we've file name (with extension) as part of string and while displaying to users we want to replace file extension from string. Here's how we can do this:
<?php
  $snippet = 'Lorem ipsum dignissim interdico meus file.exe dolore ideo.';
  echo preg_replace('/\\.[^.\\s]{3,4}?/', '', $snippet);
?>
Above function will find and replace all extensions from a string.
Tags
Submitted by ychaugule on