tqla Posted January 22, 2008 Share Posted January 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87240-solved-quick-question-about-strip_tags/ Share on other sites More sharing options...
PHP Monkeh Posted January 22, 2008 Share Posted January 22, 2008 I'd put the $value = strip_tags(trim($value)); above the str_replace() line, then don't even include it in the str_replace. So it looks like this: <?php $value = strip_tags(trim($value)); $value = str_replace("&", "and", $value); ?> Quote Link to comment https://forums.phpfreaks.com/topic/87240-solved-quick-question-about-strip_tags/#findComment-446262 Share on other sites More sharing options...
saf Posted January 22, 2008 Share Posted January 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87240-solved-quick-question-about-strip_tags/#findComment-446274 Share on other sites More sharing options...
tqla Posted January 22, 2008 Author Share Posted January 22, 2008 Thank you PHP Monkeh and saf for your help. saf, you made this so clear to me that I will look at my code a whole new way from now on! Quote Link to comment https://forums.phpfreaks.com/topic/87240-solved-quick-question-about-strip_tags/#findComment-446323 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.