Snippets

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


How to generate random string in PHP

snippets

How to generate random string in PHP Have you ever needed to generate a random password from a given set of chars in PHP? You could also probably wanted a password salt used for encrypting the user password. Well here are two solutions which I can think of at the moment to help you generate

How to get last key in an array in PHP

snippets

How to get last key in an array in PHP? Arrays can have lots of elements, some that may not be needed at one point. Let’s say that we need in some cases the last key or last element of an array in PHP, what would you do? A very good solution and clever practice

How to check if URL exists in PHP?

snippets

How to check if URL exists in PHP? Let’s say you want to check if an URL exists. You want to do that with PHP because that is what you know, and you want to perform some savings into the database if that URL exists. This can be done in various ways which will work

How to add element to array PHP

snippets

How to add element to array PHP If you are a programmer, you will need to work with arrays at some point, arrays are something referred to like a collection of elements. It is much easier to have an array with n number of elements, instead of having n number of variables. Problem Lets say

How to remove the last character in a string in PHP ?

snippets

How to remove the last character in a string in PHP ? You have a string, let’s say “1,2,3,4,5,6,7,8,” that is generated in a loop, and you want to remove the last comma that is occurred on the last position of the string, to obtain a string like this: “1,2,3,4,5,6,7,8”. 1st solution

2nd

Perl split string example

snippets

Perl split string example Perl split string function is one of the few perl functions used in string manipulation. It is similar to explode in php which will create for you an array with the pieces from the specified string. In this post snipped, you will see a quick example of how this can be

PHP explode equivalent for javascript

snippets

PHP explode equivalent for javascript Very often you have to perform operations on strings to split them, to obtain only a desired piece of it. If the string is formatted in a way that allows you to split, eg. you know the delimiters, you can use the following way to do this. Problem Let’s say

Using utf8_decode to correct diacritics words

snippets

Using utf8_decode to correct diacritics words I said in one my earlier articles that I’ve had to upgrade joomla 1.0 to joomla 3.2, not I’m not entirely sure at what point, but at the end, I’ve noticed that all my accent words were binary encoded in the database. This may or may not work in

How to search a string or array in another array in php

snippets

How to search a string or array in another array in php In this post snipped I will be showing you how to easily search for a string or an array directly in another array in php really fast and easy with step by step examples. Scenario We have the bellow array with our persons names:

Find string in array in perl

snippets

Find string in array in perl There are cases in your projects where you will most likely want to search an array for a specific element or string. There is no function like how it is in PHP for example that could do this automatically, but there is one core function that can be used

Request an article ←