how to pass variable in get without %20 %27 and retrieve back exactly what is passed i tried urlencode and decode but not works need some help
passing in url http://localhost/civilhelp/enquiry.php?cat=%27PLUMBING%20FITTINGS%20&%20SANITARY%20WARE%27
i need to remove %27 %20 used urlencode but no use
retrive only PLUMBING FITTINGS and remaining pls anybody help with a solution
i am passing it as
$cate = 'PLUMBING FITTINGS & SANITARY WARE'; it is from db
<a href="enquiry.php?cat='<?php echo urlencode($cate) ;?>'">
try to retrieve as
$category = urldecode($_GET['cat']);
$category = str_replace("'"," ",$category);
print_r($category);
$category = trim($category);
print_r($category); it just prints PLUMBING FITTINGS
Am not getting exactly aht i passed
Note: I have used urlencode and urldecode also trim
But still i can't Hope what is my problem!!
that cannot be right i tried your code and it show the correct data try this
$url = 'http://localhost/civilhelp/enquiry.php?cat=%27PLUMBING%20FITTINGS%20&%20SANITARY%20WARE%27';
$category = urldecode($url);
$category = str_replace("'","",$category);
echo $category; // result: http://localhost/civilhelp/enquiry.php?cat=PLUMBING FITTINGS & SANITARY WARE
EDIT:
i got your problem just in the cat='' change & to %26
<?php if(!empty($r['category'])){ $cat = $r['category']; $cate=substr($cat,0,25) . '';
//$cat = str_replace(' ', '', $cate);
$cat = str_replace('&', '%26', $cat); after changing it works fine // print_r($cat);?>
<a href="enquiry.php?cat='<?php echo $cat ;?>'">
enter code here
Related
Ok guys I got a situation here and I could use some help.
I get the parameters sent to me url encoded and they look like this
http://example.com/tyntec.php?sender%3D%2B16155305760%26receiver%3D%2B17874539876%26text%3Dplease+stop+sending+messages
I am trying to set my variables like this but that is not working because I guess the $_REQUEST is skipping the encoded & sign
$to = $_REQUEST['receiver'];
$from = $_REQUEST['sender'];
$text = $_REQUEST['text'];
How do I properly grab the parameters from the URL and set the variables?
Thanks in advance for helping me out.
Try this.
parse_str( urldecode( 'http://example.com/tyntec.php?sender%3D%2B16155305760%26receiver%3D%2B17874539876%26text%3Dplease+stop+sending+messages' ), $output );
var_dump($output);
Use this:
<?php
$url = 'http://example.com/tyntec.php?sender%3D%2B16155305760%26receiver%3D%2B17874539876%26text%3Dplease+stop+sending+messages
';
$url = utf8_decode(urldecode($url));
$parts = parse_url($url);
parse_str($parts['query'], $query);
echo $query['sender'];
echo $query["receiver"];
echo $query["text"];
?>
code:
<?php
include('conn.php');
$student_id = $_SESSION['student_id'];
$college_name = $_GET['college_name'];
$college_name22 = explode('(', $college_name);
if(preg_match('#\((.*?)\)#', $college_name, $match))
{
$match[1] = lcfirst($match[1]);
}
else
{
$match[1] = 'All';
}
?>
If url having string like
cstest/view.php?college_name=Agra%20Public%20Institute%20of%20Technology%20&%20Computer%20Education,%20Artoni%20(Pharmacy)
and I want to explode the following string i.e.
Agra%20Public%20Institute%20of%20Technology%20&%20Computer%20Education,%20Artoni%20(Pharmacy)
when I echo $college_name it display only (Agra Public Institute of Technology) not full name i.e (Agra Public Institute of Technology & Computer Education, Artoni) and $match[1] contain (pharmacy) which is not showing when I print $match[1] it show 'All'. So, how can I fix this problem ?
Thank You
The & has a special meaning in URL. the value of $_GET['college_name'] is exactly "Agra%20Public%20Institute%20of%20Technology%20". The & marks the start of a new parameter.
If the ampersand is properly escaped as %26 you will have a much easier time.
You could try inserting a var_dump($_GET) and see what the data is that you are actually working with.
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;
I have this kind of url from youtube, with the value of video
$url='http://www.youtube.com/watch?v=H_IkPia6eBA&';
What i need is just to get new string with value of V etc in this case
$newstring='H_IkPia6eBA&';
I dont know how long V could be, only i need to get that value of V, I have tried
$string = 'http://www.youtube.com/watch?v=oYyslNuRcwM';
$url = parse_url($string);
parse_str($url['query'], $query);
print_r($query);
Tried with this, but in CodeIgniter post, I only get empty array?
You're almost there already.
<?php
$string = 'http://www.youtube.com/watch?v=oYyslNuRcwM';
$url = parse_url($string);
parse_str($url['query'], $query);
$newstring=$query["v"]; // just this line is missing
echo $newstring;
?>
Demo
But you know something? If the url format is always going to be like that then no need for all those functions. It then can simply be
<?php
$url='http://www.youtube.com/watch?v=H_IkPia6eBA&';
echo str_replace("http://www.youtube.com/watch?v=","",$url);
?>
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');