brem13 Posted June 15, 2010 Share Posted June 15, 2010 i'm trying to get the substring from between 2 parenthesis(), is there a way to do that with the substring or explode method. basically i'm trying to get the 175 from 5'9'(175)cm Link to comment https://forums.phpfreaks.com/topic/204799-substr-between-parenthesis/ Share on other sites More sharing options...
Cagecrawler Posted June 15, 2010 Share Posted June 15, 2010 $string = "5'9'(175)cm"; $openParenthesis = strpos($string,'(') + 1; //Add 1 to not include parenthesis. $closeParenthesis = strpos($string,')'); echo substr($string, $openParenthesis, $closeParenthesis - $openParenthesis); Link to comment https://forums.phpfreaks.com/topic/204799-substr-between-parenthesis/#findComment-1072177 Share on other sites More sharing options...
brem13 Posted June 15, 2010 Author Share Posted June 15, 2010 thank you sir! it worked, however, is there a quick way you could explain the syntax tho? Link to comment https://forums.phpfreaks.com/topic/204799-substr-between-parenthesis/#findComment-1072180 Share on other sites More sharing options...
Cagecrawler Posted June 15, 2010 Share Posted June 15, 2010 - Line 1: The string to process. - Line 2: strpos finds the location of the opening parenthesis and then 1 is added to get the position of the first digit you want. - Line 3: strpos finds the location of the closing parenthesis. - Line 4: substr selects the text you want, using line 2 as the start position (the first digit) and the difference between the start and the end as the length. If you want more information, the PHP manual will explain the functions better than I could. Link to comment https://forums.phpfreaks.com/topic/204799-substr-between-parenthesis/#findComment-1072184 Share on other sites More sharing options...
brem13 Posted June 15, 2010 Author Share Posted June 15, 2010 actually, explaining it in laymans terms is better for me, that explained it perfect, thank you Link to comment https://forums.phpfreaks.com/topic/204799-substr-between-parenthesis/#findComment-1072186 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.