<?php

$html = "<html><p>para 1</p><p>نص عربي أو فارسي</p><p>para3</p></html>";
$xml = simplexml_load_string($html);
$ptags = $xml->xpath("//p");

$regex = '~[\x{0590}-\x{05ff}\x{0600}-\x{06ff}]~u';

foreach ($ptags as &$p) {
	if (preg_match($regex, (string) $p))
		$p->addAttribute('class', 'some cool css class');
}
echo $xml->asXML();

?>