I want to add a class to <p>
if it matches following expression using preg_replace
.
Following code does that however it cuts the first letter of the string (rtl language). Notice the word ہور
, the first character ہ
is being cut. How that can be fixed ?
$str = "<p>para 1</p><p> ہور سنا کنجڑا </p><p>para3</p>";
$result = preg_replace("~\p{Arabic}~u", "<p class=\"foo\">", $str, 1);
echo $result;
//output
<p>para 1</p><p> <p class="foo">ور سنا کنجڑا </p><p>para3</p>