<?php if( preg_match('/^[\x{0590}-\x{05ff}\x{0600}-\x{06ff}]/u', $string) ) { echo "rtl"; } else { echo "ltr"; }?>