SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    532
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Php strip_tags not working

    Hi guys,

    strip_tags($myvar)

    or

    strip_tags($myvar, <p>)

    will not strip the <p> tags from my string. I have read a lot of different posts but I'm not sure I trust the sources so I thought I'd ask on here as this is where I get the most sense.

    So firstly, why doesn't it always work?

    The string in question is "<p> T-Mobile* *18 *600 *unlimited *500Mb</p>"

    Can anyone spot the problem?

    Also if it doesn't work does anyone have a function solution which is short and streamlined.

    thanks
    "Persistence is the path to perfection"

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,904
    Mentioned
    139 Post(s)
    Tagged
    2 Thread(s)
    Are you sure that that is the string? It's not &lt;p&gt; T-Mobile* *18 *600 *unlimited *500Mb&lt;/p&gt;

    Look at the source of the webpage when you debug stuff like this, not at the webpage itself; it may trick you.
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    532
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Scalliio, thanks for your reply
    The problem is that this string is entered from a js based text editor plugin so I am not sure is being generated. I will have a look at the db.

    So you're saying that strip_tags would ignore that because it isn't wrapped in <> or </>?

    Which method would I use instead?
    "Persistence is the path to perfection"

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,904
    Mentioned
    139 Post(s)
    Tagged
    2 Thread(s)
    You would first use html_entity_decode (whoever came up with that function name... ) so they become "legit" <p> and </p> and then you can apply strip_slashes
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    532
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks so much for clearing that up for me, I am no stranger to php and yet it is only now that I seem to be learning some of the specifics that make it such powerful scripting language.

    I must stop brushing these things under the carpet and telling myself, "its ok you know C and C++ so you pretty much know php" cos I clearly don't know it properly LOL

    Thanks dude Have a good nite
    "Persistence is the path to perfection"

  6. #6
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,904
    Mentioned
    139 Post(s)
    Tagged
    2 Thread(s)
    No problem. And a good night to you as well
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •