3

I have a text editor where user can enter raw HTML as a description. In some cases, there are some CSS styles in the text editor. I want to skip through the CSS and work only on string.

Raw HTML

    <style type="text/css">.textleft{
    margin-bottom:10px;
    float:left; 
    display: inline-block;
    width:56%;
    text-align:left;
    padding-right:20px;
    padding-left:20px;
}
  .textleft > p { display: table-cell; height: 150px; vertical-align: middle; }


.imageblock{
    display:inline-block;
    margin-bottom:10px;
    width: 44%;
}

.textright{
    margin-bottom:10px;
    float:right; 
    display: inline-block;
    width:56%;
    text-align:left;
    padding-left:20px;
    padding-right:20px;
}

.containerz{
    display:block;
}


.featimage{
    vertical-align:middle;
    display:inline-block;
    width:53%;
    max-height:245px;
}

.features{
    vertical-align:middle;
    display:inline-block;
    width:46%;
    padding-left:30px;
}

.textright > p { display: table-cell; height: 150px; vertical-align: middle; }

@media screen and (max-width: 991px)   {
    .textleft, .textright, .imageblock{
        width:100%;   
        float:none;
        padding-left: 0px;
        padding-right: 0px;
    }   
    /*.imageblock > img { width:100%;}*/
    .containerz {text-align:center;}
    .textright > p, .textleft > p { height: 100%; }
    .textright, .textleft { margin-bottom: 0px; }
    .features, .featimage { padding-left: 0px; width:100%; float:none;}
    .features { padding-top: 10px;}
    .imageblock {margin-bottom: 25px;}
}
</style>
<h1><strong>WhiteCoat Clipboard<sup>&reg;</sup> - TEAL&nbsp;- Vertical Metric Medical Edition</strong></h1>

PHP strip_tags

$description  = utf8_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, 200) . '..',

above code only works if there are no CSS rules in $product_info['description']

for the above HTML, I get this

.textleft{ margin-bottom:10px; float:left; display: inline-block; width:56%; text-align:left; padding-right:20px; padding-left:20px; } .textleft > p { display: ..

1 Answer 1

2

I don't know if there exists a function for it, but this will do it:

$a = <<<EOH
<style type="text/css">
.textleft{
.... (your css stuff here)....
}
</style>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias blanditiis deserunt eligendi error est exercitationem ipsum laudantium minima mollitia rem! Aliquid amet aspernatur blanditiis consectetur deleniti dignissimos ducimus, illo iusto libero maxime nulla odit quasi quidem, quis quod sint unde velit vitae? Ab assumenda eos facere molestiae nesciunt provident voluptatum?

EOH;
$a = preg_replace('/<style(.*)<\/style>/s', '', $a);
var_dump($a);

output: string '
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias blanditiis deserunt eligendi error est exercitationem ipsum laudantium minima mollitia rem! Aliquid amet aspernatur blanditiis consectetur deleniti dignissimos ducimus, illo iusto libero maxime nulla odit quasi quidem, quis quod sint unde velit vitae? Ab assumenda eos facere molestiae nesciunt provident voluptatum?
' (length=382)

Sign up to request clarification or add additional context in comments.

4 Comments

I tried this but it doesn't remove any tags, output comes with the style tags
It works for me. hmm.. are you sure that in $product_info['description'] is really what you posted (verified it with a echo $product_info['description']) ?
yes that's exactly what I posted. did you try it woth my html ?
I have tried it with what I posted and what you posted, both succesfull.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.