<?php

$tmp = '1. Mathematik, LA Bachelor Gymnasien, 2015,'; // => Sonstige
$tmp = '1. Informatik, Bachelor, 2015, 1. Fachsemester'; // => Informatik
$fachrichtung = '';
if (preg_match( '/\d+\.(?P<fach>[\w\s]+)/ius', $tmp, $aMatches )) { 
   if (true === stripos($tmp, ', LA ') ) {
   	  $fachrichtung = "Lehramt";
   } else if ("Informatik" !== trim( $aMatches['fach'] ) && "Physik" !== trim( $aMatches['fach'] )) {
	  $fachrichtung = "Sonstige";
   } else {
   	  $fachrichtung = trim( $aMatches['fach'] );
   }
   echo $fachrichtung;
}