Skip to content
Advertisement

How to get a variable name as a string in PHP?

Say i have this PHP code: $FooBar = “a string”; i then need a function like this: print_var_name($FooBar); which prints: FooBar Any Ideas how to achieve this? Is this even possible in PHP?

Enumerations on PHP

I know that PHP doesn’t yet have native Enumerations. But I have become accustomed to them from the Java world. I would love to use enums as a way to give predefined values which IDEs’ auto-completion …

Best practices to test protected methods with PHPUnit

I found the discussion on Do you test private method informative. I have decided, that in some classes, I want to have protected methods, but test them. Some of these methods are static and short. Because most of the public methods make use of them, I will probably be able to safely remove the tests later. But for starting with

Can’t use certain characters in a regex

if(!eregi(“^([0-9a-z_[]*- ])+$”, $subuser)) $form->setError($field, “* Username not alphanumeric”); Can anybody tell me why it is not allowing characters such as – and *? if(!eregi(“^([0-…

How can I change a file’s extension using PHP?

How can I change a file’s extension using PHP? Ex: photo.jpg to photo.exe Answer In modern operating systems, filenames very well might contain periods long before the file extension, for instance: PHP provides a way to find the filename without the extension that takes this into account, then just add the new extension:

Calling Python in PHP

I have a Python script I recently wrote that I call using the command line with some options. I now want a very thin web interface to call this script locally on my Mac. I don’t want to go through the minor trouble of installing mod_python or mod_wsgi on my Mac, so I was just going to do a system()

Advertisement