glenelkins Posted February 19, 2009 Share Posted February 19, 2009 Hi lets say i have 2 vars like this: $var1 = 'kernel.class.php'; $var2 = 'database.class.php'; I want to rempove the .class.php so: $var1 = rtrim ( $var1, '.class.php' ); $var2 = rtrim ( $var2, '.class.php' ); Works fine! but when trimming the $var1 it comes back as 'kerne' not 'kernel' but the $var2 is fine as 'database' why is it removing the 'l' from $var1 ?? Link to comment https://forums.phpfreaks.com/topic/145895-rtrim-issue/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 19, 2009 Share Posted February 19, 2009 Because any character you put in the string as the second parameter will be trimmed. '.class.php' means to trim any ".", "c", "l", "a", "s", "p", or "h". Link to comment https://forums.phpfreaks.com/topic/145895-rtrim-issue/#findComment-765997 Share on other sites More sharing options...
farkewie Posted February 19, 2009 Share Posted February 19, 2009 Try this, <?php $var = "file.class.php"; $var = explode('.', $var); $file = $var[0]; print $file; ?> Link to comment https://forums.phpfreaks.com/topic/145895-rtrim-issue/#findComment-766011 Share on other sites More sharing options...
glenelkins Posted February 19, 2009 Author Share Posted February 19, 2009 ah right i thought rtrim just removed characters in the order i type them as a matched string. perhaps i should just use preg_match or somethign! Link to comment https://forums.phpfreaks.com/topic/145895-rtrim-issue/#findComment-766013 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.