OK, this is basic PHP stuff really, but it’s something I don’t use very often so I thought I’d add a little note to remind myself.
HTML:
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<select name="test[]" multiple="multiple">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="four">four</option>
<option value="five">five</option>
</select>
<input type="submit" value="Send" />
</form>
PHP:
<?php
$test=$_POST['test'];
if ($test){
foreach ($test as $t){echo 'You selected ',$t,'<br />';}
}
?>
Source: http://onlinetools.org/tricks/using_multiple_select.php
Something I’ve not really played around with but I may do in the near future…. a very helpful info page about Apache’s mod_rewrite stuff:
http://corz.org/serv/tricks/htaccess2.php
OK, so this is going to be a very uninteresting post, but I used the printer for my first time ever at Netbasic. I am only writing this because Sii held me at knifepoint and told me I had to blog about it or he would kill me. So here it is.
I found an interesting helper function today through the PHPDeveloper.org feed.
It’s as simple as the topic suggests - it’s a function that takes an XML formatted string and returns an array containing the results. Using the example from Michael’s msbware.com:
Example source XML:
<xmlData>
<author>
<name>John Doe</name>
<magazine>Time</magazine>
<magazine>National Geographic</magazine>
</author>
</xmlData>
Example result array with:
[xmlData][author][name] => John Doe
[xmlData][author][magazine][0] => Time
[xmlData][author][magazine][1] => National Geographic
Before you read this, I want to make one thing clear - I am not obsessive-compulsive. But some things annoy me about neat programming sometimes. Sometimes I just write new code that is neatly tabbed and aligned the way I like it. Other times I look at the old code that is around my new code. I turn on hidden characters and gasp at the spaces instead of tabs, and the whitespace at the end of most lines.
Leaving trailing whitespace is one thing, but not adhering to the project’s indentation scheme is another. Here at Netbasic, we use the TAB character to indent, not SPACE like some UNIX programs. Personally I prefer tab, as it’s neat, and you can adjust how wide each tab is in most editors, so you can lay your code out as indented or un-indented as you like. One feature I liked in UltraEdit though is the ability to remove trailing whitespace in a file. As far as I can tell, PhpED (although my new favourite editor) doesn’t have this feature.
I discovered the strange error of “syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM” today. Strange error, it’s been written about before, but to remind myself in future, it means “Double Colon” in Hebrew. The “T” is as normal meaning “Token”.
This also led me to talk to Kelvin about a way about my problem. I had a function something like this (I’ve re-written it as obviously I can’t directly post our company’s source code on the internet!!):
<?php
function SomeFunction($className)
{
$result = $className::StaticMemberFunction();
}
?>
So if you try this you’ll find that it yields the afformentioned double colon error. It’s not possible to use the :: on a variable name, it must be on a class name. Kelvin told me there’s a couple of solutions, one safe, one unsafe.
The unsafe one is to build PHP code as a string using the get_class_name on $className to statically call StaticMemberFunction(), and eval() that string. eval(), of course is unsafe and absolute care and attention needs to be made to insuring against code injection, something that could be potentially dangerous.
The safer and much easier method is to just instatiate the class. Static functions don’t have to be called statically, it’s just sometimes easier to not have to create an instance of the class just to call a function if it doesn’t access member variables. Unfortunately in this case, where we don’t know what class we’re calling, we have to do it this way, so this will work:
<?php
function SomeFunction($className)
{
$class_instance = new $className();
$result = $class_instance->StaticMemberFunction();
}
?>
Yay it works!
I discovered something new and exciting today, that Zend do an official certification. It may not mean much to… well anyone, but after reading Ben Ramsey’s post about it, and for the small price of £110 for the Zend PHP5 Certification bundle (includes a study guide, the exam voucher, and some mock tests), I think it might be worth it. Unfortunately I can’t afford it this month, but on the plus side it looks like I can take the test at Highbury College, which is of course very local to me. I think it’ll be worth it anyway…
An old article appeared in my phpdeveloper.org inbox today, about Microsoft and Zend uniting to improve Windows running PHP support. A chap called Tony Bibbs raised a question back then which I think could still be unanswerable, seeing as Microsoft’s bid to buy Yahoo! still hasn’t been accepted.
Read the rest of this entry »
Oh - I forgot to mention also that I got around to upgrading to WP 2.5. Not had much of a fiddle, so far all I can see is that the admin section had a bit of a facelift, but I’m off to bed in just a second as Hannah is waiting for me, so I shall investigate another time!
Read the rest of this entry »
I left work today with another new feeling - I wasn’t relieved to be leaving the office and going home, I was just happy that I had a nice day. It’s a strange thing how things seem to have turned on their head. Things are looking up for me at last, and I’m savouring every moment.
I really do wish Hannah could be happy too, her heart is giving her trouble and whatnot, she had her ECG today. She’s got her doc’s appointment on Tuesday and we’ll see what the result is then. I just hope she gets better soon!