いくつかのスタイルチェックの問題を回避しようとしていますが、終止符「。」を追加したいと思います。1行のコメント(「//」を含む)を持つすべての行の終わりまで。
正規表現を使用してこれを行う方法があると思いました。
どんな助けでも大歓迎ですありがとう
簡単な方法:
$result = preg_replace('%//.*%', '\0.', $subject);
エレガントな方法(まだドットがない場合は、最後にドットを追加するだけです:
$result = preg_replace('%//.*(?<!\.)$%m', '\0.', $subject);
説明:
// # Match //
.* # Match any characters except newlines
(?<!\.) # Assert that the last character isn't a dot
$ # right before the end of the line