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 336 views
1 answer 304 views
1 answer 311 views
1 answer 309 views
1 answer 351 views
1 answer 271 views
...