Jump to content

[SOLVED] Quick Question about strip_tags


tqla

Recommended Posts

Is this code applying strip_tags to all $value elements or just the ones that it performed a str_replace on?

 

$value = str_replace("&", "and", strip_tags(trim($value)));

 

I'm wondering if I need to add this too right under it to cover the other $value elements:

 

$value = strip_tags(trim($value));

 

Or does the first one suffice?  ???

 

Thank you.

Link to comment
Share on other sites

Remember: All a computer does is MATH...nothing else

 

If you have taken any moderately advanced to advanced math, you probably know that you always perform an action at the deepest layer and come out (You can remember it as "You always want to climb out of a hole" - move up from the deep)

 

Now let's analyze your code while implying what I just mentioned above:

 

$value = str_replace("&", "and", strip_tags(trim($value)));

 

1. The deapest part of your code is $value. So we will first work with that.

    - There is nothing you can do to $value at it's core level in this specific code so we move up.

2. The next is trim($value).

    - Here we have a function trim() which has the variable $value, so we will trim whatever is stored in $value

3. Now we move on to strip_tags(trim($value)).

    - This time we will perform a strip_tags operation on the "NEW" string that we got from Step 2.

4. We now move to str_replace("&", "and", strip_tags(trim($value))).

    - Here we will follow the str_replace rules and perform them on the "NEW" string that we got from Step 3.

5. Finally we have $value = str_replace("&", "and", strip_tags(trim($value)));

    - Now we assign this "NEW" string from step 4 in to a variable called $value

 

BEWARE: Since the variable name in Step 5 is the same variable name of our original (unedited) string, this original string will be completely discarded and replaced with the new string that was generated in Step 4. Therefore you will not have access to the original string once it has been modified.

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.