Re: Parsing Subject and Ticket #

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux