Replace the tag content without getting rid of any attributes : String Replace « String « PHP






Replace the tag content without getting rid of any attributes


<?php
     $string = "<a href=\"http://www.java2s.com/\">java2s.com</a><br />" ;
   
     $pattern = '/<a(.*?)>.*?<\/a>/i';
     $replacement = '<a\1>Click!</a>';
   
     $string = preg_replace($pattern, $replacement, $string);
     print($string);
?>
           
       








Related examples in the same category

1.Quantifier Syntaxes
2.str_replace: @ (at)
3.Replacing a Pattern with a Found String
4.String replace with Regular Expressions
5.What happens when multiple instances of the search string overlap?
6.String replace: index and value