Jump to content

strip_tags and line breaks


Omzy

Recommended Posts

Basically I'm using the strip_tags() function to (obviously) strip out the HTML tags from a string. The new string is then used to form a <meta description> tag.

 

What happens is when I view the source of the page (in the browser) I get the stripped string but there are loads of line breaks throughout the string. It seems like these line breaks are where the HTML tags have been stripped out. How can I get rid of these line breaks?

 

I have tried the trim() function but that doesn't seem to work. I have also tried str_replace(" ", "", $string)...

Link to comment
https://forums.phpfreaks.com/topic/166612-strip_tags-and-line-breaks/
Share on other sites

Well basically, as well outputting extra line breaks it was also outputting   in the html source. So after applying your fix above it got rid of the extra line breaks so I now get it all in-line as it should be:

 

<meta name="Description" content="   Technical Specifications: Platform: DS BBFC Rating:       Description: 100 Classic Book Collection turns your Nintendo DS into.. " />

 

Can your preg_match code be extended to take out all the  ?

No it's definitely not calling htmlentities or any other method. Not as far as I can see anyway...

 

This is just really strange, normally strip_tags() and trim() is all you need to get rid of line breaks, spaces and html tags. But I've already had to use a preg_replace function to get rid of the line breaks and will probably now need to use some other function to get rid of the  !

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.