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
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  ?

Link to comment
Share on other sites

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  !

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.