Skepsis Posted December 21, 2010 Share Posted December 21, 2010 hello, i'm creating a blockular system for my project and ran into a problem, i don't need to go much in depth since this is a simple issue. i have an array with a value: <?php ['file'] = 'articles.blocks.php' ?> i need to get just articles, .blocks.php is not global so i cannot use preg_replace or str_replace, i need to get rid of the first period, the first word, second period, and extension removed, so basically i need to find the module name, .var.php is not necessary. I am not sure how to go about this, any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/222289-string-removal/ Share on other sites More sharing options...
Adam Posted December 21, 2010 Share Posted December 21, 2010 If it's just up to the first period then you can use substr with strpos: echo substr($str, 0, strpos($str, '.')); Quote Link to comment https://forums.phpfreaks.com/topic/222289-string-removal/#findComment-1149866 Share on other sites More sharing options...
Skepsis Posted December 21, 2010 Author Share Posted December 21, 2010 that worked fantastic! thank you kindly for that and for the fast response. I was looking into preg_match but that definitely wasn't need. I've taken a bit to look over the two functions you've provided me with, but can't seem to grasp it too well. could you tell me how i'd be able to get the word after the first period? Quote Link to comment https://forums.phpfreaks.com/topic/222289-string-removal/#findComment-1149874 Share on other sites More sharing options...
Adam Posted December 21, 2010 Share Posted December 21, 2010 If you're returning multiple values from the string then you're best off using explode, as opposed to more complex string functions. You can also use list to easily extract the values into variables: list($module, $type) = explode('.', $str); Quote Link to comment https://forums.phpfreaks.com/topic/222289-string-removal/#findComment-1149878 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.