Jump to content

strip_tags issue when stripping <Span style> tag


tinmanbf

Recommended Posts

 

Hi All,

 

Hope you can help, I'm having problems with the strip_tags code, I'm having problems getting it to work with certain tags, the code below shows my issue:

 

 

$print_description = <span style="color: #ff99cc; font-size: large">4 x BLUE handmade clay feet</span>

$print_description = strip_tags($print_description); //remove html because of danger of broken tags

 

I've cut down the code to show the problem. So I want to strip the Span tags; the problem I am having is as soon as you have a style attribute with more than one attribute and you use a ; symbol strip_tag will strip the entire content of the <span>AND ALL THE TEXT IN THE MIDDLE</span>.

 

I want to just be left with '4 x BLUE handmade clay feet'

 

If I take the ; out and just have one style it works fine. I am using tiny_MCE so don't have the option not to use what it makes me use.

 

I've searched the net and have tried a few things to make it work but now I'm at a loss.

 

Any help would be gratefully received.

 

Link to comment
https://forums.phpfreaks.com/topic/228159-strip_tags-issue-when-stripping-tag/
Share on other sites

if i delete one of the attributes so I just have:

 

$print_description = <span style="color: #ff99cc">4 x BLUE handmade clay feet</span>
$print_description = strip_tags($print_description); //remove html because of danger of broken tags

 

then it works fine but as soon as I add the second attribute ...  ; font-size: large .... it stops working?

 

Here is some more of the code, maybe it's not that part that is causing the issue:

 

if ($max_description != 0) {
                 $description = stringsplit($print_description, $max_description); // so lets only show the first xx characters
                 if (strlen($print_description) != strlen($description[0])) { $description[0] = $description[0] . ".."; }
                 $print_description = $description[0];
              }

              $print_description = strip_tags($print_description); //remove html because of danger of broken tags

 

I sorten the output so could the ; be effecting this part of the script?

 

Just solved this myself, after pasting the other bit of the code it came to me; I was limiting the letters  before removing the tags, so with larger tags I would end up with no text because I would have just captured the tags and then removed them!

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.