Re: Parsing Subject and Ticket #

From: Date: Sun, 09 Feb 2014 18:04:29 +0000
Subject: Re: Parsing Subject and Ticket #
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-322801@lists.php.net to get a copy of this message
At 11:32 AM 2/9/2014, Ron Piggott wrote:
I am trying to parse an e-mail subject so it returns the subject and also the ticket # *if* this is a reply to an existing ticket. For this subject: $subject = 'Translation Idea [ Ticket 1005 ]'; my desired result is: $subject_array = array('subject'=>'Translation Idea' , 'ticket_profile_reference'=>1005 ); And for this subject: $subject = 'Translation idea'; my desired result is:
    $subject_array = array( 'subject'=>'Translation Idea', 'ticket_profile_reference'=>FALSE );
The ticket # will always be in the format: [ Ticket # ]
Don't over think this. It's probably best attacked with regex, but since I'm weak at that, here's my take at it: <?php $subject = 'Translation Idea [ Ticket 1005 ]'; list($subject,$ticket_profile_reference) = explode(' [ ', $subject); $ticket_profile_reference = ($ticket_profile_reference != '') ? trim(ltrim(rtrim($ticket_profile_reference, ' ]'), 'Ticket')) : FALSE; $subject_array = array('subject'=>$subject, 'ticket_profile_reference'=>$ticket_profile_reference); var_export($subject_array); ?> Ken

« previous php.general (#322801) next »