/    Sign up×
Community /Pin to ProfileBookmark

Why Php Filter Fails ?

Folks,

Why isn’t this filtering anything ? Nothing getting stripped!

[code]
<?php

$input = ‘<a href=”sempervivumwatsup-doc/doc.htm”>Watsup Doc ?’;

function test_input($data)
{
trim($data);
stripslashes($data);
strip_tags($data);
htmlspecialchars($data);

return $data;
}

echo test_input($input);

die;

?>
[/code]

Why in tutorials they add the:
**stripslashes($data);**
but forget the:
**striptags($data);**

https://www.tutorialspoint.com/php/php_form_introduction.htm

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@developer_webauthorApr 16.2021 — Ok,

My above code was buggy but this ain't and still not doing the filtering. Not stripping anything.
<i>
</i>&lt;?php

$input = '&lt;a href="sempervivumwatsup-doc/doc.htm"&gt;Watsup Doc ?';

function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = strip_tags($data);
$data = htmlspecialchars($data);

<i> </i>return $data;
}

test_input($input);

echo $input;

die;

?&gt;


Is it because I wrote this:

**test_input($input);**

instead of this:

**echo test_input($input);**
Copy linkTweet thisAlerts:
@developer_webauthorApr 16.2021 — This is working to see on screen what gets stripped and what not:
<i>
</i>&lt;?php

$input = '&lt;a href="sempervivumwatsup-doc/doc.htm"&gt;Watsup Doc ?';

function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = strip_tags($data);
$data = htmlspecialchars($data);

<i> </i>return $data;
}

echo test_input($input);

echo $input;

die;

?&gt;


It seems the stripslashes only strips the backward slash and not the forward shlash. Why ?

The striptags strips the forward slash ? But that should strip html tags. Not forward slashes that represent directories/folders in a url.

Don't forget to reply to my previous question before this post.

Cheers!
Copy linkTweet thisAlerts:
@NogDogApr 16.2021 — > @developer_web#1630457 stripslashes only strips the backward slash and not the forward shlash

Read the manual page, specifically the "return value" part. I.e., it's doing what is was designed to do, for specific situations you may never need to worry about. (If you are running PHP with magic quotes enabled, you're being very 1999.)

> @developer_web#1630456 Is it because I wrote this:

> test_input($input);

> instead of this:

> echo test_input($input);


Yes. If you don't do anything with the return value from a function, it just gets dropped down the computer memory toilet and ignored.
Copy linkTweet thisAlerts:
@developer_webauthorApr 17.2021 — @NogDog#1630477

Can you explain this code to me. It shows blank.

I don't understand the code. Any chance you can simplify it for me to understand it in my test ?
<i>
</i>&lt;?php
function small_numbers()
{
return array (0, 1, 2);
}
list ($zero, $one, $two) = small_numbers();
?&gt;

What is the code trying to do ?

This is confusing:

**list ($zero, $one, $two) = small_numbers();**

What is the "list" part here ?

And why is there an "=" here ?

https://www.php.net/manual/en/functions.returning-values.php
Copy linkTweet thisAlerts:
@NogDogApr 17.2021 — https://www.php.net/list

Try echoing out those 3 variables after you do the list call.
Copy linkTweet thisAlerts:
@developer_webauthorApr 18.2021 — @NogDog#1630510

I already did before opening this thread and I see the $var values echoed.

But that code is not a good example of returning more than one value. Returning values in an array.

I mean just look how confusing it is. I can guarantee you don;t write messy like that. You have a simpler way of doing it.

Now let us all see how you yourself do it. ;)
Copy linkTweet thisAlerts:
@developer_webauthorApr 18.2021 — @NogDog#1630510

NogDog,

You MAY still reply to my previous post with a simple code sample, if it's NOT too much bother.

And I will also try on my end but before I do that, tell me, which function grabs all the keys from associated arrays ? Watch how I make use of it to draw-up a simple code that is better than this complicated list() code the php manual cooked-up that I mentioned in my original post.

Let's compete NogDog, you and me. You try your best to cook-up a tiny simple code as a substitute to the list() shown on my op and I will do my beginner level best. Let's see who manages to build a very tiny & simple one. Lol!!

This will be a good game.
Copy linkTweet thisAlerts:
@developer_webauthorApr 21.2021 — @Sempervivum

Care to reply in replacement to NogDog ?

Thanks.
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...