I have a URL that contains a department name that will pull records from the database.
The URL looks like this: submissions.php?department=Settings,%20Security%20&%20Payments which is the equivalent of Settings, Security & Payments
My query needs to pull records from the table where the department is equal to Settings, Security & Payments.
How can convert that GET variable back to what I would expect it to be?
I tried html_entity_decode but it ignores the & and only gave me everything prior to that.
Whats the best way to do that?
Side note, if it was my data I would make it simple and pull it by ID but we dont have a table that has ID's for the departments.
Try urldecode()
You can see the manual here. http://uk3.php.net/urldecode
<?php
$string = "submissions.php?department=Settings,%20Security%20&%20Payments";
$decoded = urldecode($string);
echo "Original string: $string\n";
echo "Decoded string: $decoded\n";
?>
http://codepad.org/Bq1Gt30s
Use urldecode($your_URLstring)
Related
Pulling in data from a Filemaker Pro database field and trying to convert the plain text data from the field into a clickable link to google maps via PHP.
My first attempt doesnt display anything when called:
$Venue = '';
$Venue is then echoed into a UL via
<?php echo $Venue; ?>
I'm relatively new to PHP so I'm sure there is a much more semantic way of marking this up? Possibly a regex and replace, returning a preg_replace? Which is what I've been using for plain text URLs and email addresses.
Anything helps, thanks so much.
Casey - not sure there's enough context here to help you? For instance, forget the link wrapping, does
<?php echo $record->getField( 'Auctions::AIS_Venue'); ?>
actually echo the field contents to a page?
Also, not sure you really want to use nl2br anyway, as you probably don't want a break in your url ;-)
OK, in which case there are a couple of things to try. First - can you get it to run in a webviewer inside FileMaker? I suspect not, and it may be down to an encoding/filtering issue.
There are two approaches you could use.
Create a new calc field in FileMaker that filters out punctuation and converts spaces to '+'s, something like:
Filter( Substitute( Lower( Auctions::AIS_Venue ) ; [ ¶ ; "+"] ; [" " ; "+"]; ["++" ; "+"] ); "abcdefghijklmnopqrstuvwxyz1234567890+" )
and then use that field as in your PHP code, or;
Do the same calculation on the fly in PHP, something like:
$Venue = '';
That should do the trick ? ;-)
This is example what I mean:
I wanna grab result from this url web1.com/do.php?id=45944
Example output:
"pk":"bn564vc3b5yvct5byvc45bv","1b":129,"isvalid":true,"referrer":true,"mobile":true
Then, I will show data result on other site web2.com/show.php
But I just wanna see data value "pk", "1b" and "isvalid". I don't need "referrer" and "mobile" data.
So, when I access web2.com/show.php, it just show data like this:
bn564vc3b5yvct5byvc45bv 129 true
file_get_contents web1.com/do.php?id=45944
Grab this result "pk":"bn564vc3b5yvct5byvc45bv","1b":129,"isvalid":true,"referrer":true,"mobile":true
Filter and show value "pk", "1b" and "isvalid" on web2.com/show.php
So, can you help me with simple php code/script?
Sorry if you don't understand because my english.
Is this source providing JSON-formatted data? That is, with { }'s around it?
If so, use PHP's built in json_decode function. (Man page at http://php.net/manual/en/function.json-decode.php) It will parse the JSON data for you and return an associative array. For example
$your_JSON_data = '{"pk":"bn564vc3b5yvct5byvc45bv","1b":129,"isvalid":true,"referrer":true,"mobile":true}';
$your_array = json_decode($your_JSON_data);
echo $your_array['pk'] . ' ';
echo $your_array['1b'] . ' ';
echo $your_array['isvalid'];
If, for some reason, there are no JSON-style curly braces around your data, you can append them.... for example,
$proper_JSON = "{$bad_json_data}";
however, if that's the case, I'd wonder why it wasn't properly formatted in the first place. In that case it may be safer to use the PHP explode function (http://php.net/manual/en/function.explode.php)
I have a stored url in a MySQL database. (http://example.com/page.php?ex='$_GET[ex]') When I retrieve it to create a dynamic link it gives me http://example.com/page.php?ex=%27.$_GET[ex].%27 and of course won't work.
I can't seem to be able to get (sorry had to use it!) the $_GET variable.
To be exact the cell contains...
Submit Risk Assessment<button>Create / Edit</button>
It seems that the string have been encoded by urlencode
You should decode the url encoded string
$a = urldecode('http://example.com/page.php?ex=%27.$_GET[ex].%27');
echo $a;
// print the url
Not really answering the question, but my solution was to create a separate field in the database for the url only. I then used deceze's suggestion of sprintf and it works perfectly.
if(!empty($row[buttonlink])){
$ex = $_GET[ex];
$rawlink = $row[buttonlink];
$format = '<button>Create / Edit</button>';
$buttonlink = sprintf($format, $rawlink, $ex);
}
Only had a small number of buttons to do and they could all be labelled 'Create / Edit'. I could add another field to have the label called into the sprintf too.
I have saved some information in database with MySQL, now i want to show them, cause it contains some tags like <div>, <p>, etc. I just want them showed as raw html code, anyone can tell me how? i try to use `html_entity_decode(), but it does not work.
Example:
<div><b>Prénom/Nom : </b>tantantan tan</div>
<div><b>Pseudonyme : </b>nickname</div>
<div><b>Résidence principale : </b>69001 Lyon 1er</div>
<div><b>Autre résidence : </b> Place bellecours 69002 Lyon 2e</div>
====== in fact , i need to do in this way.
#using serialize() method
$data = serialize($_SESSION);
$sql = "Insert into sessioninfo `data` values('$data')";
and then
# I assume you can retrieve the data from database and assign to the following variable
$data = unserialize($row['data']);
perfectly resolve my problem. thanks everyone.
This is not an mysql_real_escape_string data but html_specialchars() encoded data
you can do the reverse with htmlspecialchars_decode()
Try html_entity_decode:
echo html_entity_decode($string);
Would recommend not to apply htmlspecialchars when you save the database.
The sanitize should be applied when sending output, if necessary.
I'm having this problem that's driving me nuts.
I've got a MySQL database in which there is a table that contains a text field. I am querying the table in PHP and trying to put the content of the text field for each row into a var.
I am doing something like this:
for ($i=0;$i<$nbrows;$i++){
$id = $data[$i]['ID'];
$description = $data[$i]['DESCRIPTION'];
$mystring .= '<div>'.$id.': '.$description.'</div>';
}
DESCRIPTION is my text field.
I'll pass on the details. The $data array is built from mysql_fetch_array($result). I also tried using objects instead, as I use mysql_fetch_object for all my other routines, but there is no change.
Anyway, the problem is this: if I do "echo $description;" then it works. I am getting my text field data as expected. The problem is that I don't want to output it directly, but add it to a concatenated string, and that is not working. What happens in that case is it seems to be taking $description for some kind of array or object. To make the above example work, I have the replace the string with:
$mystring .= '<div>'.$id.': '.$description[0].'</div>';
So in the concatenated string code, if I treat $description as an array, it works, but obviously I am getting only one letter. (it doesn't actually seem to be an array because I can't implode it).
I tried a million things but I just can't make this work unless I use echo, but that is not what I am trying to do.
There is no issue with fields that aren't text.
Thanks for any ideas!
There is nothing visually wrong with the code you pasted, maybe if you could also add the fetching function as well, we might be able to help you further.
Maybe you could post a var_dump of your $data array?
Have you tried $mystring .= "<div> $id : $description </div>";
Ack, well, you know, hours spent on this and then it becomes obvious after I decide to post for help. This is just because of text encoding/escaping and nothing else. I just didn't see well enough where the problem was actually happening.
Thanks for taking the time to read and respond!