Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Tuesday, July 31, 2012

lookbehind regex in PHP

Today, I was facing a problem how to split something like following text
a="Some Text" b="Some more Text" c="Even more text about \" this text\"" d="aaaaaaa"
into array, into pairs key => value. I couldn't just use explode(), because spaces could be inside the quotes..

After a little searching, I founded that solution lies in lookbehind regular expressions.. Nifty things ^_^

This
/(?<![\\\|=])\" /
expressions would split it into following array:
array (
  0 => 'a="Some Text',
  1 => 'b="Some more Text',
  2 => 'c="Even more text about \" this text\"',
  3 => 'd="aaaaaaa"',
)
so exactly what we wanted :)

Tuesday, June 12, 2012

PHPUnit_Util_Log_XML

I was doing some work in PHPUnit and one of the request from company was export to xml.. So I was thinking, how to do that? I found some tutorials online, but I run into error Class 'PHPUnit_Util_Log_XML' not found in...

I found out that PHPUnit_Util_Log_XML was renamed into PHPUnit_Util_Log_JUnit ...

I just thought I can save someone searching..

Monday, July 11, 2011

CodeIgniter form helper

Today, I was developing some form generating script for one guy and I need a quick way for creating form. For this purpose I used to use Form class from Nette framework, but I requires a bunch of files etc., so it was a little overkill for my script consisting of exactly one file.

So I remembered, that CodeIgniter has form helper, which was exactly what I needed. But there was problem, this helper was dependent on the framework itself, it was not just "set of standalone functions".

So I stripped it down, removing call for framework and leaving helper file, which can be used as standalone script.

If I remember correctly now, there is only one different to original helper. My helper is set only for 'accept-charset="UTF-8"' but original gets this setting from framework. I was thinking about add possibility to set this, but because helper is a bunch of functions, there is not any static variable you can just set (I wanted to avoid name collisions...). And anyway, who is not using UTF-8 now, right?

But it is on github, so if someone has meaningful changes (like accept-charset, new functions, ...), do not hesitate to commit your code.

There is the link: https://github.com/volftomas/Standalone-form_helper