Is there a built-in function for PHP for me to check whether two arrays contain the same values ( order not important?). For example, I want a function that returns me true for the following two inputs: Edit: I could have sorted the two arrays and compare them, but as I am such a lazy guy, I would still prefe…
What is the best way to split a string into an array of Unicode characters in PHP?
In PHP, what is the best way to split a string into an array of Unicode characters? If the input is not necessarily UTF-8? I want to know whether the set of Unicode characters in an input string is a subset of another set of Unicode characters. Why not run straight for the mb_ family of functions, as the firs…
Is there a good implementation of partial file downloading in PHP?
I’m writing a PHP script that allows the user to download a file. Basically the idea is to prevent the file being downloaded more than X times, since it is paid content, and the link should not be spread around. Since the files will be pretty large, it should be good to implement resuming. I’ve re…
Generating a truly unique order id in PHP?
I’m considering using this: http://phpgoogle.blogspot.com/2007/08/four-ways-to-generate-unique-id-by-php.html My idea is to use a mixture between 2 and 3. But my question is that, although the …
Why I am getting Cannot pass parameter 2 by reference error when I am using bindParam with a constant value?
I’m using this code and I’m beyond frustration: try { $dbh = new PDO(‘mysql:dbname=’ . DB . ‘;host=’ . HOST, USER, PASS); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); …
Why use sprintf function in PHP?
I am trying to learn more about the PHP function sprintf() but php.net did not help me much as I am still confused, why would you want to use it? Take a look at my example below. Why use this: When this does the same and is easier to write IMO: Am I missing something here? Answer sprintf has all
How to create an error 404 page using PHP?
My file .htaccess handles all requests from /word_here to my internal endpoint /page.php?name=word_here. The PHP script then checks if the requested page is in its array of pages. If not, how can I simulate an error 404? I tried this, but it didn’t result in my 404 page configured via ErrorDocument in t…
How do I throttle my site’s API users?
The legitimate users of my site occasionally hammer the server with API requests that cause undesirable results. I want to institute a limit of no more than say one API call every 5 seconds or n calls per minute (haven’t figured out the exact limit yet). I could obviously log every API call in a DB and …
What is PHPSESSID?
I’m playing around with cookies. And I dont have any cookies called PHPSESSID. Do i need it? Can i remove it? Whats the “function” of it? Prints: Answer PHP uses one of two methods to keep track of sessions. If cookies are enabled, like in your case, it uses them. If cookies are disabled, it…
Manipulate a string that is 30 million characters long
I am downloading a CSV file from another server as a data feed from a vendor. I am using curl to get the contents of the file and saving that into a variable called $contents. I can get to that part …