note 38799 added to function.file

From: Date: Wed, 07 Jan 2004 12:33:21 +0000
Subject: note 38799 added to function.file
Groups: php.notes 
Request: Send a blank email to php-notes+get-63066@lists.php.net to get a copy of this message
Re: Afterburner's comment on passing URLs via GET parameters. Your regex method is neither sufficient or necessary. There are characters other than & which will cause problems, and using a full-blown regex is rather heavyweight. This is what the functions urlencode() and rawurlencode() are for. Before incorporating your parameter-URL into a link, call urlencode() on it. urldecode() will then transform this string back into the original URL, *BUT* you don't normally have to call this as PHP will automatically urldecode() incoming GET parameters for you (you only need call it explicitly if you're using this encoding to pass the URL through some other medium, such as a data file of your own format.) Eg. $myurl = "http://somewhere/script1.php?param1=val1&param2=val2"; printf("<a href=\"http://somewhere/script2.php?url=%s\">Clicky</a>", urlencode($myurl)); [in script2.php:] $myurl = $_REQUEST['url']; # already decoded You should then be able to pass $myurl directly to file() or any other URL enabled function. ---- Manual Page -- http://www.php.net/manual/en/function.file.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38799 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38799&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38799&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#63066) next »