PHPStorm Regex Replace "Malformed Replacement String"

If you are struggling using PHPStorm to find and replace code with Regex rules then this is your solution. The problem is that when using the $ sign in your replacement string it confuses it because PHP Storm uses the $ sign to represent sub pattern replacements. Take the following example code: $data = array(); $form=$page->find('form.edit_product', 0); //standard inputs $inputs = $form->find('input[type="text"]'); foreach($inputs as $input){ $data[$input->name]=$input->value; } //radio inputs $inputs = $form->find('input[type="radio"]'); foreach($inputs as $input){ if($input->checked){ $data[$input->name]=$input->value; } } //checkbox inputs $inputs = $form->find('input[type="checkbox"]'); foreach($inputs as $input){ if($input->checked){ $data[$input->name]=$input->value; } } //textareas $textareas = $form->find('textarea'); foreach($textareas as $textarea){ $data[$textarea->name]=$textarea->innertext; } And trying to replace the key being used in the data array with a processed one calling a method $this->dataName($key) to generate the following code: $data = array(); $form=$page->find('form.edit_product', 0); //standard inputs $inputs = $form->find('input[type="text"]'); foreach($inputs as $input){ $data[$this->dataName($input->name)]=$input->value; } //radio inputs $inputs = $form->find('input[type="radio"]'); foreach($inputs as $input){ if($input->checked){ $data[$this->dataName($input->name)]=$input->value; } } //checkbox inputs $inputs = $form->find('input[type="checkbox"]'); foreach($inputs as $input){ if($input->checked){ $data[$this->dataName($input->name)]=$input->value; } } //textareas $textareas = $form->find('textarea'); foreach($textareas as $textarea){ $data[$this->dataName($textarea->name)]=$textarea->innertext; } You might try the find pattern: \$data\[\$([^-]+)->name\] And the replace pattern: \$data\[\$this->dataName(\$$1->name)\] However this will give you the dreaded “malformed replacement string” Error The solution is simply to triple escape your dollar signs, so the replacement pattern becomes: \\\$data\[\\\$this->dataName(\\\$$1->name\)\] And it works, woot! Read On →

Migrate to Google Apps - Google Apps Reseller

We are big fans of Google Apps and have built a large portion of our business processes around the system. For this reason we have absolutely no problem recommending the service to our clients and have assisted numerous clients with a migration to the system. The first benefit you will get is your emails migrated over and a much better email service. You have the option of using normal IMAP access so you can continue to use your preferred desktop application however we suspect that you will start to use the web interface as it is really quite powerful with some unique features that you can not access on a normal desktop client. Read On →

Bash Terminal Rename Programmatically

If you have a load of terminals open you might find it handy to be able to rename the window title on the fly. You can do this easily by copying this code into your ~/.bashrc file (or even pasting it into your terminal if you like) function nameTerminal() { [ "${TERM:0:5}" = "xterm" ] && local ansiNrTab=0 [ "$TERM" = "rxvt" ] && local ansiNrTab=61 [ "$TERM" = "konsole" ] && local ansiNrTab=30 ansiNrWindow=0 # Change tab title [ $ansiNrTab ] && echo -n $'\e'"]$ansiNrTab;$1"$'\a' # If terminal support separate window title, change window title as well [ $ansiNrWindow -a "$2" ] && echo -n $'\e'"]$ansiNrWindow;$2"$'\a' } If you have pasted this into your ~/.bashrc file you need to launch a new terminal or run: source ~/.bashrc From this point the function is now ready to use and you can run: nameTerminal "My Custom Terminal Window Title" Now you can easily choose the terminal you want based upon the window title. Read On →

Linux Sun Java repo

Recently I setup a machine with Linux Mint. One of the things that was I needed to install was an up to date version of Sun Java. However, for various reasons, this no longer appears in the official repos. Thankfully there is a different repo available here http://www.duinsoft.nl/packages.php?t=en where you can download the latest version and ensure that it is updated

Form File Upload Limits with PHP

If you have a form designed to handle file uploads which is failing due to file size then you might like this: $arrayMaxes = array( 'upload_max_filesize' => intval(ini_get('upload_max_filesize')), 'post_max_size' => intval(ini_get('post_max_size')), 'memory_limit' => intval(ini_get('memory_limit')) ); $maxUploadSize = min($arrayMaxes); foreach ($arrayMaxes as $key => $value) { if ($value == min($arrayMaxes)) { $minimumOfThree = $key; break; } } echo "The maximum file size you can upload is $maxUploadSize, this is due to the php.ini setting $mininimumOfThree"; This will calculate the smallest value that will be allowed based upon php.ini settings. Read On →

Firefox and Responsive Web Design

Responsive web design is an excellent way to make a site work really well for a variety of different screen sizes without having to serve more than one design to users. Responsive web design does pose additional challenges however. Some of the challenges for you, as the developer, are being able to implement, test and debug the design implementation. Fortunately built in to Firefox’s arsenal of developer tools is an interface for exactly that! Read On →