Creating a URL (HTTP Query) with PHP without escaping special charaters [duplicate] - php

This question already has answers here:
http_build_query() without url encoding
(10 answers)
Closed 6 years ago.
I want this:
datasetid=GHCND&locationid=ZIP:28801&startdate=2010-05-01&enddate=2010-05-01
I have this:
$data=['datasetid'=>'GHCND','locationid'=>'ZIP:28801','startdate'=>'2010-05-01','enddate'=>'2010-05-01'];
I tried this:
exit(http_build_query($data));
I got this:
datasetid=GHCND&locationid=ZIP%3A28801&startdate=2010-05-01&enddate=2010-05-01
How can I prevent ZIP:28801 from being escaped as ZIP%3A28801?

You need to urldecode the string like this:
urldecode(http_build_query($data));

Related

Get part of string PHP [duplicate]

This question already has answers here:
PHP - parse current URL
(6 answers)
Closed 2 years ago.
How to get a part of string using PHP?
I have a string like this.
https://test-app.com/admin/api/2019-10/orders.json?limit=2&page_info=eyJpZHMiOiIyMDY3MTczMTEzOTg3LDIwNjU0ODU0MzA5MTUsMjA2NTQ3OTI3MDUzMSwyMDYyODE3MzI5MjgzIiwibGFzdF9pZCI6MjA2NTQ4NTQzMDkxNSwibGFzdF92YWx1ZSI6IjIwMjAtMDMtMTcgMTg6MTc6NTkiLCJkaXJlY3Rpb24iOiJuZXh0In0
I want only the link.. like this
orders.json?limit=2&page_info=eyJpZHMiOiIyMDY3MTczMTEzOTg3LDIwNjU0ODU0MzA5MTUsMjA2NTQ3OTI3MDUzMSwyMDYyODE3MzI5MjgzIiwibGFzdF9pZCI6MjA2NTQ4NTQzMDkxNSwibGFzdF92YWx1ZSI6IjIwMjAtMDMtMTcgMTg6MTc6NTkiLCJkaXJlY3Rpb24iOiJuZXh0In0
That's not just a string it's a URL so use URL and path functions:
$parts = parse_url($str);
echo basename($parts['path']).$parts['query'];

replace particular value from url [duplicate]

This question already has answers here:
PHP, Delete parts of a URL variable [duplicate]
(3 answers)
Closed 4 years ago.
I want to replace '/50' with URL.my URL is
http://localhost/CI/admin/pcustomer/cprofile/50?customer=18267&mobile=&nearby=
I want url as
http://localhost/CI/admin/pcustomer/cprofile?customer=18267&mobile=&nearby=
From that little info in your question, this seems to be the simplest way to achieve "I want to replace '/50' with URL"
$url = str_replace('/50', '', 'http://localhost/CI/admin/pcustomer/cprofile/50?customer=18267&mobile=&nearby=');

How to decode Ascii code in a Character in PHP [duplicate]

This question already has answers here:
URL Decoding in PHP
(6 answers)
Closed 6 years ago.
I got the string in this format
solr/?key=color&facet=Blue%26keyword%3Dwoo
However, I want to get it in this format
solr/?key=color&facet=Blue&keyword=woo
Try urldecode:
$url = urldecode("solr/?key=color&facet=Blue%26keyword%3Dwoo");
// = solr/?key=color&facet=Blue&keyword=woo

PHP decoding html encoded characters [duplicate]

This question already has answers here:
URL Decoding in PHP
(6 answers)
Closed 6 years ago.
I have problem decoding html encoded character using php, what should i do?
Below is the sample input.
%D8%A7%D8%AB%D8%A7%D8%B1%D9%87 %D8%A7%D9%84%D9%85%D8%B1%D9%87
Below is the sample output i want.
اثاره المره
Use PHP's urldecode function:
urldecode("%D8%A7%D8%AB%D8%A7%D8%B1%D9%87 %D8%A7%D9%84%D9%85%D8%B1%D9%87");

How can I get URL (with some parameters)? [duplicate]

This question already has answers here:
Get URL query string parameters
(11 answers)
Closed 6 years ago.
I have a form on page, with url like this:
site.com/form.index.html?ref=https://login....
And I get page URL via this code:
http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]
But as result I get not full URL, just this:
site.com/form.index.html
How can I get full URL?
You want to add the query string:
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]$_SERVER[QUERY_STRING]";
Additionally, you may replace the http bit with $_SERVER[REQUEST_SCHEME]:
"$_SERVER[REQUEST_SCHEME]://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]$_SERVER[QUERY_STRING]"

Categories