Jump to content

strip_tags?


ginerjm

Recommended Posts

So I am doing a script to read some emails coming into an address that I have piped to it.  Done this before and had success.  Problem now is strip_tags.  Trying to remove some spurious html codes in the email the easy way or so I thought.  What's happening is this

 

A line that contains an email address such as this:

 

From: <user@domain.com>

 

is being stripped out to this:

 

From: <user@domain.com>

 

I thought that strip_tags would just strip out the < and > chars but it is not.  Any ideas?

Link to comment
Share on other sites

The HTML entities do not come from strip_tags(). Appearently you're also using htmlspecialchars() or htmlentities().

 

strip_tags() is generally a very poor choice. This function is supposed to remove HTML tags, but it's way too primitive to do that correctly. Chances are it will just mangle the entire input. In your case, for example, it removes the whole e-mail address, which is probably not what you want.

Link to comment
Share on other sites

The purpose of strip_tags() is to remove HTML and PHP tags from a string. More information can be found here:

http://php.net/manual/en/function.strip-tags.php

 

In your case, however, it looks you're running the email address(es) through something like htmlentities() before running strip_tags(). That's where entities like < come from.

 

If you're just looking to remove some specific characters, you could look into using something like str_replace():

http://php.net/manual/en/function.str-replace.php

Link to comment
Share on other sites

The input comes from an email and looking at the raw source I got before I added the strip tags I saw an email address enclosed in < and >.  There was no other function applied to this - I simply thought that I could remove the < and > with this function.  Apparently I can't

Edited by ginerjm
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.