tjmbc Posted May 29, 2008 Share Posted May 29, 2008 anyone know how I can put line breaks in a string every time there is a digit. i have a mysql text field that has a string like this: 3/4 went to the store 12/4 went to the store 8/16 had a popsickle i want to take that string and make it like this: 3/4 went to the store 12/4 went to the store 8/16 had a popsickle any idea's? Link to comment https://forums.phpfreaks.com/topic/107744-working-with-a-text-string/ Share on other sites More sharing options...
Gighalen Posted May 29, 2008 Share Posted May 29, 2008 /stumped This is the best I have.. Is there any any way you can add a : between the entries? like when inserting them into the DB you could do $new = $old.":";, then insert new into the db. If you can, you can just use the explode function and add a <br> when parsing. Link to comment https://forums.phpfreaks.com/topic/107744-working-with-a-text-string/#findComment-552334 Share on other sites More sharing options...
Gighalen Posted May 29, 2008 Share Posted May 29, 2008 add a <br> when parsing* Link to comment https://forums.phpfreaks.com/topic/107744-working-with-a-text-string/#findComment-552335 Share on other sites More sharing options...
effigy Posted May 29, 2008 Share Posted May 29, 2008 <pre> <?php $data = '3/4 went to the store 12/4 went to the store 8/16 had a popsickle'; echo preg_replace('%(?<=\s)(?=\d+/\d+)%', '<br>', $data); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/107744-working-with-a-text-string/#findComment-552573 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.