I am trying to get IP details from this page http://www.geoplugin.net/json.gp?ip= in PHP.
But sometimes it returns some characters like this š. Is there any way to replace it with the respective character (š - š)?
Try function html_entity_decode()
Related
I am facing a problem with passing query string. In my query string the value containing a # tag when i use $_REQUEST['string'] its only return the value which is write before of # tag. There is any way to solve this problem...
My Problem is
localhost/index.php?string=adc#123
Value i get using
$_REQUEST['string']
is only abc value after # tag not capture.
please suggest me solution for this problem...
use urlencode($string) before sending in php file.
I assume it is because # is a reserved character which is used as an anchor to access components in your web pages, like http://example.org/index.php#header that will point to the tag which as "header" as identifier.
Did you try to escape this character or to use urlencode(...) so it won't be interpreted as an anchor? Doc : http://php.net/manual/fr/function.urlencode.php
When redirecting to that page generate the query string like -
header('location:index.php?str='.urlencode('abc#123'));
It will encode the query string value.
From the below URL
http://nis.com/projects/cc_intranet/mauth/lib_test/?authenticate=7JaoTs9NM4xdTnZpQE+q73X4N0oqMvX+BSlLrsqDeUL6VwaXt/91ZYOviomSIt/DvPuEjKAvip5++++++++++UZuVQWJ53mQa83Dz5EX4sfbjI1iXQjHrdwa2Ecca1bLe6MHis9UuSs
When i use "$_GET['authenticate'];" and then print it,
i get the the following output where "+" doesn't display.
7JaoTs9NM4xdTnZpQE q73X4N0oqMvX
BSlLrsqDeUL6VwaXt/91ZYOviomSIt/DvPuEjKAvip5
UZuVQWJ53mQa83Dz5EX4sfbjI1iXQjHrdwa2Ecca1bLe6MHis9UuSs
Is there any way how to get the exact same result ?? (i.e) in my case the "+" symbol has not been passed to the $_GET['authenticate'] while printing it ???
+ is reserved character in GET queries to represent a space character. If you really need + character in your query you need to replace it with %2B:
authenticate=7JaoTs9NM4xdTnZpQE%2Bq73X4N0oqMvX%2BBSlLrsqDeUL6VwaXt/91ZYOviomSIt/DvPuEjKAvip5%2B%2B%2B%2B%2B%2B%2B%2B%2B%2BUZuVQWJ53mQa83Dz5EX4sfbjI1iXQjHrdwa2Ecca1bLe6MHis9UuSs
urlencode php function is a good way to create a proper URL with all reserved symbols escaped.
urldecode function is for decoding such URLs.
I have several strings that look like this:
Lasklé
Jones & Jon
I am trying to send them via the foursquare API to be matched, however it is failing with these characters. Is there a way to sanitise these so they only include English letters i.e. the results would be:
Lasklé
Jones Jon
As it appears using file_get_contents requests both with the 'é' and the '&' in the URL is causing issues.
I checked how the request was sent and realised that the '&' is uneeded and is causing the issues, is it possible to remove all non Letters/Numbers from the name?
What do the strings look like before you pass them? If your string looks like 'Lasklé' then I think you are using the wrong character set when reading the string, try using UTF-8.
If the string looks correct before you pass it on you should try urlencode the string first.
you can use preg_replace() function to replace the part of string using regex
to keep only letters you can use as follow it will also remove space( add \s from expression to keep space)
preg_replace('/[^a-zA-Z]/','',$string);
to keep space in the string or any character to keep you can add it in []
preg_replace('/[^a-zA-Z\s]/','',$string);
Use this to escape (space and '-'). Good for making a custom URL
$string=preg_replace("/[^A-Za-z0-9\s\/\-]/", '', $string);
I have a database of 2 word names and they have a space between them however in order for my api call to work I need a %20 between the first and second word.
Currently mysql_query returns Anas platyrhynchos and I need it to return Anas%20platyrhynchos
any quick solution?
You can use PHP urlencode. That should solve your problem.
you can use the replace() function to return the correct string from your query
replace(columnname,' ','%20')
Alternatively you can use the urlencode() function to do this in your PHP code
You can do this on the PHP side using urlencode
You will need to urlencode the returned result from the database. This will add %20 and other special URL characters I am assuming you need.
Use Replace function.
Select Replace(colName, ' ', '%20')
I wrote a script that when you enter a textbox, it will open an invisible iframe to a .php file with $_GET of what they wrote into the textbox.
However, for example, if I type: '<3' in it, this is what happens.
PHP determins that the $_GET[s] is blank! Users cant put a simple <3 symbol without getting that error.
Another problem is quotes, if I write any quotes, it will end the entire SRC property.
What should I do? Should I do something with javascript, or even PHP? Please let me know!
Thanks!
Use urlencode to encode the inputted string into a valid one for URL use.
Also be very cautious when allowing user input into your PHP script through the URL. Make sure you do proper checks/sanitization, especially if database operations are involved.
It looks like your iframe is generated by JavaScript, so all those answers that include PHP functions are useless. The data isn't even reaching PHP, so how can any PHP function hope to help?
Instead, try using urlencode from PHPJS, since none of JS's functions really handle all cases well, and this makes it easy for you to use PHP's urldecode to retrieve the data.
You need to encode that character as <.
Regarding double quotes, you can use this trick.
attr='Your string can "contain double quotes"'
or
attr="Your string can 'contain double quotes'"
but while specifying variable=values in url, you don't need to user double quotes, you can directly assign the values.
like
url="test.php?var1=123&var2=345"
rest about sending the <3 characters, you can check for url encoding in javascript & PHP whichever applicable!