Snippets
Some little pieces of code that will help you solve your problems faster.
For and foreach loop in php
How to create a while loop in PHP
How to create a while loop in Javascript

How to create a while loop in Javascript As I said in one my earlier articles, I’ll try porting every script to all programming language we’ve set the category for, this time is for javascript. Scenario Create a counting script that stops once it reaches 10 and alerts the user the execution has finished. Solution
How to create a while loop in perl
Creating arrays and hashes in perl

Creating arrays and hashes in perl I’m sure for those users looking for dynamically storing their information they will most likely rely at some point on arrays. Here are some quick snippets on how to create arrays and associative arrays in perl (hashes). Creating an array in perl Arrays are preceded by the symbol “@”,
Convert variable to string in PHP

Convert variable to string in PHP PHP is a loosely typed language and assigns types to variables depending what is assigned to it. Sometimes you will want to transform a given variable into a string format and obtain a similar output with “ToString()” method in Java or .NET. This could be done easily with one of the following
How to parse URL using javascript

How to parse URL using javascript In certain cases you may want to parse a URL using javascript, although I don’t specifically recommend this, rather you should use a php approach, server side. Javascript can be manipulated and if passing the URL somewhere and then actually doing work with the result, you may have surprises
How to parse url using php
How to strip spaces out of a string in perl

How to strip spaces out of a string in perl You have a variable string that may have blank spaces at the end of the string or at the start of the string and you need to remove these spaces so that you can make use properly of the value of that variable. Scenario
1 2 |
//You want to strip spaces from the left side and right side of the bellow string and obtain "username" $val_string= ' username '; |
How to explode a string on upper case characters

How to explode a string on upper case characters Problem You have a string with the following value “thisStringMustBeSplittedAfterUpperCase” and you want to obtain every word separately in an array, splitted after upper case. Solution
1 |
$chunks = preg_split('/(?=[A-Z])/', $string, -1, PREG_SPLIT_NO_EMPTY); |
Output The output of the $chunks array obtained with a var_dump($chunks) will be:
1 2 3 4 5 6 7 8 9 |
array (size=8) 0 => string 'this' (length=4) 1 => string 'String' (length=6) 2 => string 'Must' (length=4) 3 => string 'Be' (length=2) 4 => string 'Splitted' (length=8) 5 => string 'After' (length=5) 6 => string 'Upper' (length=5) 7 => string 'Case' (length=4) |
Solution in a function
1 2 3 4 5 6 |
function upperCaseSplit($string){ return preg_split('/(?=[A-Z])/', $string, -1, PREG_SPLIT_NO_EMPTY); } $string = 'thisStringMustBeSplittedAfterUpperCase'; var_dump (upperCaseSplit($string) ); |