strip_tags or other solution

105 views Asked by At

I have this text in mysql adding even directly but do not want to lose the labels only the styles and formats that tenien

<p style="margin-bottom: 20px; padding: 0px; border: 0px;"><span style="line-height: 1.428571429;">Allí, el club crema</span><p>

use strip_tags but removes the entire label

strip_tags ($ data, "<p>");

I want it that way:

<p>Allí, el club crema<p>

I hope your help, thank you very much beforehand for your answers

2

There are 2 answers

0
Mitya On

Warning, anti-pattern: using REGEX on mark-up is generally a bad idea. However it's sometimes more convenient, so to hell with it:

$data = preg_replace('/(<\w+) [^>]+/', '$1', $data);
0
giorgio On

There is no php function for that. The strip tags function will strip the tag completely, and allowing a tag will keep the tag in place, including the attributes. You'll need to load the html in a xml parser and reconstruct the output, or, and I would advise you to go that way, use regex to strip out any html attributes (after you've stripped away the tags you don't need anyway. See also this question