Snippets

Some little pieces of code that will help you solve your problems faster.


For and foreach loop in php

snippets

For and foreach loop in php For and foreach loops are mostly used when working with arrays, but not only that of course. In my other examples, I created a simple snipped to show you the while loop in php, same example can be created with For loop. Scenario We have a small array and

How to create a while loop in PHP

snippets

How to create a while loop in PHP In this post snipped I’ll show you an easy way to create simple while loops and multiple or nested while loops. Scenario Create a counting script that stops once it reaches 10 and it also prints the count to the user once the execution has finished. Solution

How to create a while loop in Javascript

snippets

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

snippets

How to create a while loop in perl This post snipped is to show you how to create a while loop using perl, obviously this is possible in almost every programming language. Scenario You have to make some checks or print something until a certain limit or count. For eg. you want to print a

Creating arrays and hashes in perl

snippets

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

snippets

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

snippets

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

snippets

How to parse url using php In certain cases, even in my recent made cpanel plugin, I had to parse the url for me to clear their resource cache. The use cases for this are a lot, there are a lot of manipulation reasons for this as well as solutions. Scenario I’ll take the same

How to strip spaces out of a string in perl

snippets

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

How to explode a string on upper case characters

snippets

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

Output The output of the $chunks array obtained with a var_dump($chunks) will be:

Solution in a function

Request an article ←