How to add attribute to HTML tag in PHP

1 Answer

0 votes
$html = '<a href="https://www.collectivesolver.com/" title="php">cs</a>';

$s = preg_replace('/(<a\b[^><]*)>/i', '$1 style="text-decoration:none;">', $html);

echo $s;
  
  
    
        
/*
run:
        
<a href="https://www.collectivesolver.com/" title="php" style="text-decoration:none;">cs</a>
      
*/

 



answered Sep 20, 2019 by avibootz

Related questions

1 answer 249 views
1 answer 221 views
1 answer 218 views
1 answer 213 views
1 answer 259 views
1 answer 183 views
...