変数に格納された文字列があります。この文字列は次のように表示されます。
$sec_ugs_exp = ''; //Empty one
$sec_ugs_exp = '190'; //Containing the number I want to delete (190)
$sec_ugs_exp = '16'; //Containing only a number, not the one Im looking for
$sec_ugs_exp = '12,159,190'; // Containing my number at the end (or in beginning too)
$sec_ugs_exp = '15,190,145,86'; // Containing my number somewhere in the middle
190番号が存在する場合は削除し、番号が最後にあるか単独でない限り、その後に付けられたコンマも削除する必要があります(その場合、コンマはありません)
したがって、前に書いた例では、次のようなリターンを取得する必要があります。
$sec_ugs_exp = '';
$sec_ugs_exp = '';
$sec_ugs_exp = '16';
$sec_ugs_exp = '12,159';
$sec_ugs_exp = '15,145,86';
私の英語について申し訳ありません。preg_replace などを使用してみましたが、常にカンマの検出に失敗していました。