Skip to content

Instantly share code, notes, and snippets.

@joerx
Created December 19, 2014 04:22
Show Gist options
  • Save joerx/bce177f4087d30c0efcc to your computer and use it in GitHub Desktop.
Save joerx/bce177f4087d30c0efcc to your computer and use it in GitHub Desktop.
Strip leading/trailing slashes from a path-like string
<?php
// Replace '#' with whatever substitute desired, use '' to strip
echo preg_replace('@^/|/$@', '#', '/foo/'); // #foo#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment