n3mesis125 Posted November 28, 2008 Share Posted November 28, 2008 Hey folks, I'm looking for away to put in line breaks at certain patterns in text. Not sure if this is possible, but I'll give an example string and then what I'd like to see come out of it. <?php $string = "3.2 Here is the infor for this one 4.5 This is a test 5.0 Here we go"; ?> What I'm trying to do is search for an integer pattern for the numbers and use a line break. So the only thing at the moment that I can see could throw it off is if there is one in the beginning. I'd like to see the above string put into an array of <?php $myArray = array( [0] => '3.2 Here is the info for this one', [1] => '4.5 This is a test', [2] => '5.0 Here we go'); ?> Is this possible? Thanks, n3m. Quote Link to comment https://forums.phpfreaks.com/topic/134690-preg_match-help/ Share on other sites More sharing options...
DeanWhitehouse Posted November 28, 2008 Share Posted November 28, 2008 So at each number (2.3 etc.) you want it to go into an array and then arrange them into an order highest to lowest. If so i think a mixture between explode and i think it is called sort(); should work http://www.php.net/explode http://uk3.php.net/manual/en/function.sort.php Quote Link to comment https://forums.phpfreaks.com/topic/134690-preg_match-help/#findComment-701358 Share on other sites More sharing options...
.josh Posted November 29, 2008 Share Posted November 29, 2008 dunno if this is the best way, but it seems to work... preg_match_all("/(\d\.\d[^\d]*)/",$string, $result); Quote Link to comment https://forums.phpfreaks.com/topic/134690-preg_match-help/#findComment-701393 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.