Question: There are lines:

```
echo "1111111111111; 2222222222; 8; 2; 34,12,2,3,5,1; UNKNOW;"

```

or

```
echo "1111111111111; 2222222222; 8; 2; 34,12,2,3,5,1,5,12,45,34; UNKNOW;"

```

or

```
echo "1111111111111; 2222222222; 8; 2; 3; UNKNOW;"

```

How to take the value of the last character ";" and to the last comma ","?

Answer: 
You can use delay(idle time) into consideration. Like suppose I am typing in search text box If I am idle for 200ms, 400ms or whatever time you want, You can call an AJAX request.

If I type salman it will call api for 6 times. but suppose we will have idle time. we will call when user idle for that specific time.

To implement it in angular, you can use. $watch or bootstrap directives
You already accepted the answer but I want to share some code with you.

```
myapp.factory('formService', ['$http', '$filter', '$q', '$timeout', function ($http, $filter, $q, $timeout) {
    var service = {};
    service.delayPromise = null;
    service.canceler = null;
    service.processForm = function (url, formData, delay) {
        if (service.delayPromise)
          $timeout.cancel(service.delayPromise);
        if (service.canceler)
          service.canceler.resolve();
        service.canceler = $q.defer();
        service.delayPromise = $timeout(function (service) {
          return service;
        }, delay, true, service);
        return service.delayPromise.then(function (service) {
          service.delayPromise = null;
          return $http({
              method  : 'POST',
              url     : url,
              timeout : service.canceler.promise,
              data    : formData
          });
        })
    }
    return service;
]);

```

What does this do. It provides `formService` having `processForm` function, with accepts `url`, `formData` and `delay`.

`processForm` function delays submitting with `$timeout` service. If there are already exist delayed or pending submission it just cancels it.

And in your controller.

```
myapp.controller('myCtrl', ['formService', function (formService) {
    $scope.formData = {};
    $scope.pageData = {};
    $scope.$watchCollection('formData', function (formData, oldData, scope) {
      if (!angular.equals(formData, oldData)) {
        var event;
        formService.processForm(formData, event, 500).then(function (response) {
          if (response.data instanceof Object)
            angular.copy(response.data, scope.pageData);
        });
      }
    });
}]);

```