preg_last_error_msg Fonksiyonu

preg_last_error_msg işlevi, düzenli ifade işlevleriyle çalışırken meydana gelen son hata hakkında insan tarafından okunabilir bir mesaj döndürür. Bu, yalnızca hata kodunu döndüren preg_last_error işlevine kullanışlı bir alternatiftir.

Sözdizimi

phppreg_last_error_msg(): string

Örnek

Geçersiz bir düzenli ifade çalıştırmayı deneyelim ve hata mesajını alalım:

php<?php
  preg_match('/invalid(regex/', 'test string');
  echo preg_last_error_msg();
?>

Kodun çalıştırma sonucu:

php'No ending matching delimiter found'

Örnek

Backtrack limiti aşıldığındaki hata mesajını kontrol edelim:

php<?php
  ini_set('pcre.backtrack_limit', 1);
  preg_match('/(\d+)+$/', str_repeat('1', 1000));
  echo preg_last_error_msg();
?>

Kodun çalıştırma sonucu:

php'Backtrack limit exhausted'

Ayrıca Bakınız

  • son PCRE hatasının kodunu döndüren preg_last_error işlevi
  • bir düzenli ifadeyle eşleştirme gerçekleştiren preg_match işlevi