- preg_replace: documentation ( source)
<?php
$inputs = [
'בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת הַשָּׁמַיִם וְאֵת הָאָֽרֶץ',
'בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ',
];
foreach ($inputs as $input) {
$output = preg_replace('/[\x{0591}-\x{05AF}\x{05BE}\x{05C0}\x{05C3}]+/u', '', $input, -1, $count);
echo !$count ? "no change" : "Replacement Count: {$count}\nBefore: {$input}\n After: {$output}";
echo "\n---\n";
}