all.
I have different behavior of function urldecode() in PHP 5.2.x. Especially you will be able to see it with Wikipedia as good example.
Firstly, my page where I have results of that function has meta:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
Than I'm using function:
$url = urldecode($url);
echo $url;
Here is example of $url variable:
http://ru.wikipedia.org/wiki/%D0%91%D1%80%D0%B5%D1%81%D1%82
It will be decoded good. Result: "Брест"
http://ru.wikipedia.org/wiki/%CC%EE%EB%EE%E4%E5%F7%ED%EE
It will not be converted good. Result: ���������, but should be "Молодечно".
What's wrong? Why? I'm tried to use all functions from function.urldecode.php at PHP web-site, but it didn't give me any successful results
Here is quick example of code to test in PHP:
<?php
$url = array();
$url[] = "http://ru.wikipedia.org/wiki/%D0%91%D1%80%D0%B5%D1%81%D1%82";
$url[] = "http://ru.wikipedia.org/wiki/%CC%EE%EB%EE%E4%E5%F7%ED%EE";
foreach ($url as $value) :
echo urldecode($value) . "<br/>";
endforeach;
?>
Thanks in advance!
Not sure where you've taken that url, but the correct utf-8 one for "Молодечно" is:
$url = 'http://ru.wikipedia.org/wiki/%D0%9C%D0%BE%D0%BB%D0%BE%D0%B4%D0%B5%D1%87%D0%BD%D0%BE';
echo urldecode($url);
Your one is cp1251 encoded
As said zerkms, the following url is cp1251 encoded. To convert it to UTF-8, just use this:
$url = 'http://ru.wikipedia.org/wiki/%CC%EE%EB%EE%E4%E5%F7%ED%EE';
echo iconv("Windows-1251","UTF-8",urldecode($url));
//output: Молодечно
Related
This is my problem. I explain:
I use Firefox. If I set the browser language to English, the following page displays text in Spanish, but the currency in dollars.
Link
The same URL, If I set the browser language to Spanish, the texts are displayed in Spanish and currency in Euros.
I created a script with PHP using JSON: How I can set the language for calls?
The following code, ALWAYS returns the English language:
<?php
$url = "http://steamcommunity.com/market/search/render/?l=spanish&start=0&count=20¤cy=3&category_730_Weapon%5B%5D=tag_weapon_awp&appid=730&query=Man-o%27-war";
$json_object= file_get_contents($url);
$json_decoded = json_decode($json_object);
//precios
preg_match_all('/<span style="color:white">(.*)<\/span>/',$json_decoded->results_html, $sor);
foreach($sor[1] as $k => $v)
{
echo $v."<br/>";
}
?>
I want the currency Euros. I tried adding the following modifications, but the currency result is always English:
<html lang="es">
<head>
<meta http-equiv="Content-Language" content="es"/>
</head>
<body>
<?php
$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
echo $locale."<br/>";
$options = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: es\r\n" .
"Cookie: foo=bar\r\n")
);
$context = stream_context_create($options);
$url = "http://steamcommunity.com/market/search/render/?l=spanish&start=0&count=20¤cy=3&category_730_Weapon%5B%5D=tag_weapon_awp&appid=730&query=Man-o%27-war";
$json_object= file_get_contents($url,false,$context);
$json_decoded = json_decode($json_object);
//precios
preg_match_all('/<span style="color:white">(.*)<\/span>/',$json_decoded->results_html, $sor);
foreach($sor[1] as $k => $v)
{
echo $v."<br/>";
}
?>
</body>
</html>
Thank you for your help. Greetings.
You have a typo. Specifically, in your url. You are saying ?l=espanish. It should be ?l=spanish:
http://steamcommunity.com/market/search/render/?l=spanish&start=0&count=20¤cy=3&category_730_Weapon%5B%5D=tag_weapon_awp&appid=730&query=Man-o%27-war
Edit
I don't have any more answers unfortunately, but I came across the following SO answer which might be helpful. It would seem that the currency shown is contextual - I guess you need to be logged in via your script?
https://stackoverflow.com/a/22623700/312962
Anyway, I hope this helps!
for the currency you have ¤cy=
3: USD
2: € (i believe, try it)
let me start by saying that I have no idea how to formulate this question, I have spend the last two days looking for some ways to to the following.
I send some information encoded using base64 as follow....
Values are:
Lóms Gruñes
this values came from an input box
beacuse of that I do this
$name = htmlentities(( $_POST ['name'] ) , ENT_NOQUOTES, 'UTF-8');
$midn = htmlentities(( $_POST ['midn'] ) , ENT_NOQUOTES, 'UTF-8');
the output for this should be
Lóms Gruñes
And that is what gets encode, until that everything is fine, and I can do whatever I need with that, in this case I'm going to encode it using base64
$datas ='&name='. $name .'&midn='. $midn;
$bd = base64_encode($datas);
// Now lets send that info to another file..
header( 'Location: other.php?d=$db' ) ;
So the url will be something like
domain.com/other.php?d=TCZvYWN1dGU7bXMgR3J1Jm50aWxkZTtlcw==
So now lets decode it so that it can be saved...
$ds = base64_decode($_GET['d']);
parse_str($ds, $params);
$name = htmlentities($params['name'], ENT_NOQUOTES);
$midn = htmlentities($params['midn'], ENT_NOQUOTES);
It looks pretty straight forward isn't it... but here is the problem because when I try to use the values nothing happen... lets say I just want to echo it...
echo $name . '<br>';
echo $midn;
What I get is
L
Gru
so where is the ó and the ñ?
ok, let say I don't encode anything so the URL will look like this...
domain.com/other.php?name=Lóms&midn=Gruñes
// and the I use echo like this:
echo $_GET['name'] . '<br>';
echo $_GET['midn'];
// the output is
L
Gru
Even if I put : header ('Content-type: text/html; charset=utf-8'); after the <?php ... nothing happen... so, the question... how can I get the ó as a value or better yet, how can I send the í,ó,ñ,á...etc as is in the url domain.com/file.php?data=íÄÑó and retrive it as is and save it as is and display it as is...
I;m not sure if this has some relevant information, the data is going to be saved in a DB, the DB is InnoDB, utf8_general_ci
Thank you for taking the time...
Always escape/encode for the technology you're using.
To get the UTF-8 encoded values from the form submission:
$name = $_POST['name'];
$midn = $_POST['midn'];
To output those into HTML:
<p><?php echo htmlspecialchars($name, ENT_COMPAT, 'UTF-8'); ?></p>
To embed them in a URL:
$url = sprintf('foo.php?name=%s&midn=%s', rawurlencode($name), rawurlencode($midn));
// or
$url = 'foo.php?' . http_build_query(array('name' => $name, 'midn' => $midn));
In foo.php, to get the values back:
$name = $_GET['name'];
$midn = $_GET['midn'];
And again, to output those into HTML:
<p><?php echo htmlspecialchars($name, ENT_COMPAT, 'UTF-8'); ?></p>
And that's basically all you need to do. Always escape values using the right function for the medium, don't escape more or earlier than you need to.
First of all, if you want to decode htmlentities try html_entity_decode().
For encoding the url try urlencode().
Example from php.net:
<?php
$query_string = 'foo=' . urlencode($foo) . '&bar=' . urlencode($bar);
echo '<a href="mycgi?' . htmlentities($query_string) . '">';
?>
Hope it helps!
May be this will work for you . Instead of using htmlentites I used rawurlencode and rawurldecode function .
Below is same code
First get the values from the
$name = rawurlencode('Lóms Gruñes'); use can use //( $_POST ['name']
$mid = rawurlencode('Gruñes'); and here ($_POST ['midn'] )
then
echo $datas ='name='. $name .'midn='. $midn;
$en = base64_encode($datas);
Append this on next url . Then get the value and decode it using base64_decode function
$dd = base64_decode($en);
parse_str($dd);
echo $name;
echo $midn;
Can someone help me how to extract the url parameters from the following url using GET method in php?
http://domainname.com/?formBuilderForm%5BFormBuilderID%5D=29&formBuilderForm%5Brandomizer%5D=508398db941a26.20741366&formBuilderForm%5Bvw_sre_ticker_name%5D=TPX&formBuilderForm%5Bvw_sre_entry_price%5D=100&formBuilderForm%5Bvw_sre_entry_date%5D=21%2F10%2F2012
I believe the variable name is formBuilderForm [FormBuilderID] and value is 29. I tried the following code but it didn't work.
<?php
$_vw_sre_ticker_name_in = $_GET["formBuilderForm [FormBuilderID ]"];
echo 'vw_sre_ticker_name'.$vw_sre_ticker_name_in;
?>
I believe, it something to do with ASCII and Non-ASCII stuff.
%5D stands for [ in url encodings
So you could probably try
<?php
$_vw_sre_ticker_name_in = $_GET["formBuilderForm[FormBuilderID]"];
echo 'vw_sre_ticker_name'.$vw_sre_ticker_name_in;
?>
You needed to remove the spaces.
However as pointed out by Seth, this is really really basic debugging a simple
print_r($_GET);
Would have provided you with the information you needed rather than asking on Stackoverflow.
You can use foreach on $_GET
foreach($_GET as $key=>$value) {
echo $key . ':' . $value;
}
I'm attempting to run the script referenced here
<?php
$url = 'index.php?option=com_content&view=article&catid=334:golfeq&id=2773:xcelsiors&Itemid=44';
parse_str(parse_url($url, PHP_URL_QUERY), $vars);
echo "Variables:\n";
print_r($vars);
$id = reset(explode(':', $vars['id']));
echo "The id is $id\n";
$id = intval($vars['id']);
echo "Again, the id is $id\n";
Unlike the example shown - which works - on my station, the variable array shows that "&" is encoded to "amp;" causing that script not to work for me.
When I output the variable array from the example, I get variables like [amp;id]
How can that scriptbe modified with the "&" decoded so it will work on my station?
Thanks for your help
simple solution is
$url = html_entity_decode('index.php?option=com_content&view=article&catid=334:golfeq&id=2773:xcelsiors&Itemid=44');
I would appreciate some help here:
What I want to do:
remove &itemsperpage=10 from:
http://localhost/thi/search/filter.html?type=featured&page=2&itemsperpage=10
and create a link from it:
http://localhost/thi/search/filter.html?type=featured&page=2&itemsperpage=15
here's what I have come up with so far:
<a href="<?php echo url::site(url::current()) . http_build_query($_GET) // don't know what follows ?>"
the framework functions I'm using are:
url::current() = returns current url in controller/action format
url::site() = returns absolute url i.e http://localhost/site/controller/action
so I have to remove '&itemsperpage' from the resulting string in the http_build_query function
but I am having trouble with character encodings and such! please help!
so here's the problem with character encoding:
$needle = '&itemsperpage';
$querystring = http_build_query($_GET) . '<br/>';
// echo $querystring . '<br/>';
$pos = strpos($querystring, $needle);
$remove = substr($querystring, ((int)$pos));
echo substr(str_replace($remove, '', $querystring), 1); // returns ';'
I can't remove the string '&itemsperpage' from the result of http_build_query which is:
'type=featured&page=2&itemsperpage=10' and functions like strstr outputs nothing
I would just do this:
$array = $_GET;
$array['itemsperpage'] = 15;
Then just use your code, but with the new variable (and the ?):
<a href="<?php echo url::site(url::current()) . '?' . http_build_query($array)">
The HttpQueryString class has several methods for getting, setting, modifying query strings and 'translating' their charsets.
You can achieve the effect you're looking for by removing the itemsperpage element from the $_GET array before building the query string.
unset($_GET['itemsperpage']);
And then just use the code you already wrote:
<a href="<?php echo url::site(url::current()) . http_build_query($_GET); ?>">
EDIT: I misread your post. I thought you only wanted to remove the field / value pair from the GET request. All you have to do is overwrite the value with the value you want:
$_GET['itemsperpage'] = 15;
And then use the code you already wrote.