PHP - Urlencode Help
I have an address in a variable, I pass this address to a google maps page/function that geocodes it and returns the street view.
Heres an example of a link: Code: [Select] <a href="mapget.php?address=<?php echo urlencode(strip_tags($comaddress));?>" name="mapit">Map It</a> The address' come from either a curl or dom request so I have been trying to strip and trim them as much as possible but the urls come out looking like... Code: [Select] www.mysite.com/mapget.php?address=7855+N+SOMESTREET+AVE+SOMECITY++++++++++++++++++++++%2C+CA+11111My maps only seem to be getting the street... I am using urldecode($address) on the receiving page and when I echo $address on the receiving page it looks completely correct. Any ideas? Similar Tutorialsim using urlencode() to replace special characters in the url. It works on spacs, replacing them with '+' but it isnt working on a special character i have tried, the exclamation mark. Is this the right function to use for this? and if so why isnt it working for me? Code: [Select] function create_url($str) { $str = urlencode($str); return $str; } function decode_url($str) { $str = urldecode($str); return $str; } i use the function create_url() for the link and use decode_url() when the link is clicked so i can display the proper name. eg: Code: [Select] $forum_url_name = create_url($row['f_name']); and when viewing the forum: Code: [Select] $forum_name = decode_url($_GET['f_name']); Should we always use urlencode() when passing values through GET? If not, when is it should we NOT use it? Thanks i have a textarea in my form. If my validation script detects an error it will send it to the same page with what they had in that textarea encoded in the url. The script detects the $_GET['variable'], decodes it, and stores it as the default in the textarea so they don't have to retype it all again. The problem is the apostrophes add 7 slashes when it gets added back to the textarea. heres the relevant snippets.. Code: [Select] <?php function clean_post($variable) { $cxn = mysqli_connect($host,$user,$passwd,$dbname) or (mysqli_error($cxn)); return mysqli_real_escape_string($cxn, strip_tags($variable)); } $description = clean_post($_POST['description']); $description = str_replace(array('\r\n', '\r', '\n'), ' ', $description); $description = urlencode($description); $base = "http://mywebsite.com/"; $url = $base."?mm=1&tt=".$description; $location = "Location:".$url; die(header($location)); and then to output it in the textarea Code: [Select] <?php $tt = urldecode(strip_tags($_GET['tt'])); <textarea id=location name=location maxlength="140" > <?php echo $tt; ?> </textarea> and this is what my url ends up looking like http://mysite.com/wordpress/?mm=3&tt=what\\\%27s+the+deal%3F and this ends up in my textarea "what\\\\\\\'s the deal?" I am placing this in the PHP sections because I think you all will know this answer the quickest. I am creating a podcast. I have created the XML file successfully. I have placed the file on my server and have gotten one of my podcast clients (Media Monkey) to pick it up and the mp3 files within it successfully. My issue is that when i try an get iTunes to work with it there is problems. iTunes will read the XML, but will not download the mp3's. I'm pretty sure I know why, but there is a huge catch-22 in the deal. To protect my content my CDN offers a method by where I add some query parameters to the end of the mp3 file to protect it from illegal downloads. It look like this (not actual file) Code: [Select] http://www.sitename.com/2011-03-14.mp3?px-hash%3Db42c227e36ef27aee6e96ae9c4f32214%26px-time%3D1300704254Using this string in the XML makes it validate correctly. The issue is because this link is urlencoded, the XML validates, but iTunes will not process the link as a valid link. Now if I remove the urlencoded part of the link, the XML will not validate and then iTunes will not even read the XML file. This is the link without encoding. Code: [Select] http://www.sitename.com/2011-03-14.mp3?px-hash=98c7759588a9add0728350dd69871cdf&px-time=1300731722 See where I'm going? Anyone have a solution? How do I get around this catch-22? I need a way to pass the un-encoded link in the XML file, but still make it validate. Thanks for your help. (yes i see the links are different. Its ok as an example.) Just a small question really. If you use "urlencode()" for example if I am using a GET. Should I then do urldecode where a script then uses the GET variable? Hi, I'm trying to do the following: Code: [Select] $name = $_GET['thename']; $to = "some@email.com"; $subject = "Subject of Email"; $message = "Click this link: http://mysite.com?$name" $headers = "From: Me" . "\r\n" . "Reply-To: my@email.com" . "\r\n" . "X-Mailer: PHP/" . phpversion(); mail($to, $subject, $message, $headers); The problem I'm experiencing is that the Get function retrieves "/thename=First+Last name", which converts to a broken link in the message (because of the "+" in the url). How would I use urlencode to make sure the Get replaces the + with a %20 in this instance? It doesn't seem that I can use php in the message itself. Thanks! |