Answer the question
In order to leave comments, you need to log in
How to remove all attributes from a tag except some?
Hello!
There is a line:
<img title="тест" id="hh" alt="fff" src="/test/" align="left" width="500" dddd="dd" height="300">
Answer the question
In order to leave comments, you need to log in
$subject = '<a attr1="val1" attr2 = "" attr3 href="/link/?pa=234kjh&ff=09" attr4="val4" title="title">привет anchor 245</a>';
$pattern = '/((?:href|title)=\"[^"]+\").+?((?:href|title)=\"[^"]+")[^>]{0,}>([^<]+)/i';
preg_match($pattern,$subject,$match);
array_shift($match);
$text = array_pop($match);
$attrs = join(' ',$match);
$a_new = '<a '.$attrs.'>'.$text.'</a>';
echo htmlspecialchars($a_new);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question