Reputation: 47
When text with HTML tags inside it are inputted into a web-form (e.g <em>john</em>
), how does it appear to the PHP processor?
I did some experiments with the example above and found that the form was sending the query string %3Cem%3Ejohn%3C%2Fem%3E
is that how it would appear?
How could i fix this so that it appears as typed: <em>john</em>
?
Upvotes: 0
Views: 63
Reputation: 22741
A string in which all non-alphanumeric characters except -_. have been replaced with a percent (%)
sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type. This differs from the » RFC 3986 encoding (see rawurlencode()) in that for historical reasons, spaces are encoded as plus (+) signs. It is an encoded, To get an typed content, you can use urldecode()
$str ='<em>john</em>';
echo $Encoded = urlencode ( $str ); //OP %3Cem%3Ejohn%3C%2Fem%3E
echo urldecode ( $Encoded );
Upvotes: 0
Reputation: 2956
"%3Cem%3Ejohn%3C%2Fem%3E"
In the above statement % specifies whitespace
.its browser dependent ,some browser replaces whitespace with '%' and some with '+'
if you want to decode than you can do that by php function rawurldecode();
the syntax of which is string rawurldecode ( string $str ).
Now about querystring:
when you are sending your data via GET method,the data which you send is formed into "name=value" form and its goes to the server.
example:
consider you have a form like this
<form method="get" action="a.php">
name:<input type="text" name="name">
</form>
and you insert name as rahul
then the query string will be "name=rahul" ,the value of which you can retreive in the server side using $_GET
or $_REQUEST
Upvotes: 1
Reputation: 6226
You can use the rawurldecode function to decode the string.
rawurldecode("%3Cem%3Ejohn%3C%2Fem%3E")
Upvotes: 0