Skip to content

Instantly share code, notes, and snippets.

@alixaxel
Created January 30, 2013 09:56
Show Gist options
  • Save alixaxel/4672080 to your computer and use it in GitHub Desktop.
Save alixaxel/4672080 to your computer and use it in GitHub Desktop.
<?php
public static function Enclose($string, $delimiter = null)
{
if (strlen($string = trim($string)) > 0)
{
$string = sprintf('%2$s%1$s%2$s', trim($string, $delimiter), $delimiter);
}
return $string;
}
@xeoncross
Copy link

Is the sprintf to protect against float/int/booleans being cast incorrectly from something like this?

$string = $string ? $delimiter . $string . $delimiter : '';

@alixaxel
Copy link
Author

@xeoncross: No, not really - I'm just used to sprintf. That's a nice minification BTW. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment