Insert Line Break When date is found

Discussion in 'PHP' started by adamjblakey, Jun 2, 2011.

  1. #1
    Hi,

    I have a 100's of strings like e.g:

    
    6-11-08 no pastoral care, no social work, I need to try general office on Ext 55905, Called through, NA at11.38 - call back. 6-11-08 called through at 14.53…. NA so sent samples C/o GO Mgr. TO DO 7-11-08 DONE 22.12.08, called through for the mgr of general office, turns out GO mgr is the hospital mgr. called and no answer at 11.46 so left msg to call me back. 14.1.09, got email from switch, so sent her an email. DONE Email bounced back, call on frid 
    
    Code (markup):
    What i want to do is use a function to find any reference to a date e.g. 0-00-00 or 00-00-00 or 00.00.00 etc and if found then add a line break. At the moment this is just one big block of text so is difficult to read.

    How would i go about doing this?

    Thanks in advance.
    Adam
     
    adamjblakey, Jun 2, 2011 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi,

    You can try something like this:
    $s='6-11-08 no pastoral care, no social work, I need to try general office on Ext 55905, Called through, NA at11.38 - call back. 6-11-08 called through at 14.53…. NA so sent samples C/o GO Mgr. TO DO 7-11-08 DONE 22.12.08, called through for the mgr of general office, turns out GO mgr is the hospital mgr. called and no answer at 11.46 so left msg to call me back. 14.1.09, got email from switch, so sent her an email. DONE Email bounced back, call on frid';
    echo preg_replace("#(\d{1,2}[\-\.]\d{1,2}[\-\.]\d{2})#m","$1<br />",$s);
    PHP:
    Regards :)
     
    koko5, Jun 2, 2011 IP
  3. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #3
    great seems to work fine :)
     
    adamjblakey, Jun 2, 2011 IP