Skip to content

Instantly share code, notes, and snippets.

@objectivehtml
Created September 30, 2011 17:54
Show Gist options
  • Save objectivehtml/1254485 to your computer and use it in GitHub Desktop.
Save objectivehtml/1254485 to your computer and use it in GitHub Desktop.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$plugin_info = array(
'pi_name' => 'Rtrim',
'pi_version' => '1.0',
'pi_author' => 'Justin Kimbrell',
'pi_author_url' => 'http://objectivehtml.com/',
'pi_description' => 'Removes characters form the end of a string.',
'pi_usage' => Rtrim::usage()
);
class Rtrim
{
public function __construct()
{
$this->EE =& get_instance();
$remove = $this->EE->TMPL->fetch_param('remove');
$string = $this->EE->TMPL->fetch_param('string');
$trim = $this->EE->TMPL->fetch_param('trim');
if($string === FALSE)
show_error('You must define a string parameter');
if($trim === FALSE)
show_error('You must define a trim parameter');
if($remove)
{
$remove = explode('|', $remove);
foreach($remove as $remove_string)
{
if(strstr($string, $remove_string))
{
$string = str_replace($remove_string, '', $string);
}
}
}
$this->return_data = rtrim($string, $trim);
}
public static function usage()
{
ob_start(); ?>
{exp:rtrim string="some string to trim/" trim="/"}
{exp:rtrim string="http://www.wonderifthisworks.com/" trim="/" remove="http://|https:|www."}
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment