To better learn web development, I’m trying to write a PHP page that will let me upload and download files from a server, which I’ve done in ASP before. I am however, tripping over something that reason says should be simple, but I’m not able to find an answer for it. Here’s the pretty…
Tag: php
JetBrains WebIDE: PHP variable type hinting?
Is there a way to hint WebIDE that a variable has some type? I have to iterate an array of objects, and there’s no auto-completion available. This helps in ZendStudio: I know there’s a feature in JetBrains to declare an array of objects: But this works only with function’s return type. Answe…
How to reduce the number of if-else statements in PHP?
I found that there are many if-else statements, especially nested if else statements, these statements make my code less readable. How to reduce the number of if else statements in PHP? My tips are as follows: 1.Use a switch statement when it is suitable; 2.use exit() statement when it is feasible; 3. Use ter…
Tracking the views of a given row
I have a site where the users can view quite a large number of posts. Every time this is done I run a query similar to UPDATE table SET views=views+1 WHERE id = ?. However, there are a number of disadvantages to this approach: There is no way of tracking when the pageviews occur – they are simply increm…
Variable type hinting in Netbeans (PHP)
Just curious if there’s a way in netbeans to give type hints for regular variables, so that intellisense picks it up. I know you can do it for class properties, function parameters, return types, etc. but I can’t figure out how to do it for regular variables. It’s something that would really…
Using regex to extract username from email address
My string of text looks like this: I need to get just the part before the @ and nothing else. The text is coming from a simple XML object if that matters any. The code I have looks like this: Sometimes the username might have numbers or an underscore before the @ symbol, which is where the regex stops it
How do I PHP-unserialize a jQuery-serialized form?
Using $(‘#form’).serialize(), I was able to send this over to a PHP page. Now how do I unserialize it in PHP? It was serialized in jQuery. Answer You shouldn’t have to unserialize anything in PHP from the jquery serialize method. If you serialize the data, it should be sent to PHP as query p…
Passing arrays as url parameter
What is the best way that I can pass an array as a url parameter? I was thinking if this is possible: or how about this: Ive read examples, but I find it messy: Answer There is a very simple solution: http_build_query(). It takes your query parameters as an associative array: will return http_build_query() ha…
PHP gdLib 8-Bit PNG with alpha
how is it possible to save my image, created with gd, as an png-8? it saves as gif with transparent channel well – but I want to use png-8. Best Regards, Beerweasle Answer Using imagesavealpha() and a transparent bg color should do the trick… Based on dfilkovi’s code:
curl error 18 – transfer closed with outstanding read data remaining
when retrieving data from a URL using curl, I sometimes (in 80% of the cases) get error 18: transfer closed with outstanding read data remaining Part of the returned data is then missing. The weird thing is that this does never occur when the CURLOPT_RETURNTRANSFER is set to false, that is the curl_exec funct…