Re: Parsing Subject and Ticket #

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

 



Well I would have used pcre on the subject but since you start off parsing yourself...

$idx = strpos($subject, " [ Ticket ");
if ($idx) {
	// Probably is my kind of title
	$title = substr($subject, $idx + 1);
	$ticket = substr($subject, $idx + 9, -2);
	$subject_array = array( ‘subject’=>$title, ‘ticket_profile_reference’=>$ticket );
} else {
	// Some other kind of subject
	$subject_array = array();
}

On Feb 9, 2014, at 11:32 AM, 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 # ]
> 
> The following is what I have tried so far.  The first line of code is returning a syntax error.  Apparently it doesn’t like the simplified ‘if’.
> 
> I am asking for help to see how others would do this.
> 
> <?php
> 
>    $subject_array['subject'] = trim( substr( $subject , 0 , ( strpos( $subject , "[ Ticket " ) > 0 ) ? strpos( $subject , "[ Ticket " ) : strlen( $subject ); );
> 
>    $ticket_profile_reference = (int)trim( substr( $subject , ( strpos( $subject , "[ Ticket " ) + 9 ) , ( strpos( $subject , " ]" ) - ( strpos( $subject , "[ Ticket " ) + 9 ) ) ) );
> 
>    if ( $ticket_profile_reference == 0 ) {
> 
>        $subject_array['ticket_profile_reference'] = FALSE;
> 
>    } else {
> 
>        $subject_array['ticket_profile_reference'] = $ticket_profile_reference;
> 
>    }
> 
>    print_r( $subject_array );
> ?>
> 
> Ron Piggott
> 
> 
> 
> www.TheVerseOfTheDay.info 


-- 
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