You can use a regular expression to add or replace an attribute in HTML element.
The preg_replace() function searches string matches to the pattern and replaces with replacement.
Suppose this is your HTML element.
$html = '<p class="dif-cl">Visit DataInFlow</p>';
Now if you want to add style attribute use the following code.
$result = preg_replace('/(<pb[^><]*)>/i', '$1 style="color:red;">', $html);
Output:
<p class="dif-cl" style="color:red">Visit DataInFlow</p>
Question and answer is powered by AnsPress.io