You are here

snippet - Magento 2: Module is not listing
18 Oct, 2018
When you copy a custom module to app/code directory. Magento does not pick it up automatically. You need to run this.
snippet - Number to words in PHP
24 Jul, 2018
Helper function for converting numbers to words. There is same function available in PHPs NumberFormatter class, but using it is not always possible, since it's not enabled by default.
snippet - PHP: http request function, alternative to curl or file_get_contents
12 Mar, 2018
Handles any HTTP request correctly. This is a flexible and powerful HTTP client implementation of GET, POST, PUT or any other HTTP requests. The reason I built this was due to use of url arguments...
snippet - PHP: First x characters of a string
2 Nov, 2017
Get first n amount of characters from a string. You could use substr for that, but you will get empty results when there are special characters. Thus multibyte string method is the right way to go.
snippet - PHP: Instagram to RSS feed
2 Aug, 2017
Instagram gives out json feed. You can use this little php snippet to create rss feed from the given json. The script leverages paging, which enables you to control the items count in the output feed.
snippet - PHP: Encode Url for Curl
23 May, 2017
PHP
This snippet encodes urls for curl. If you use special letters like äõöü in url, then you get a bit different url parsing from browsers than curl in PHP. You would think that you could use php's own...
snippet - PHP: Fix url query parameters starting with
19 May, 2017
PHP
Snippet shows you how to fix url query parameters starting with "...
snippet - PHP: Check url for valid response code 200
9 Jan, 2017
PHP
Check the HTTP Status Code of the website header using PHP. Check that url is giving valid response code of 2xx. You can modify this for different purposes. For detecting 404 not found only or...
snippet - Soap request with NTLM authentication
6 Dec, 2016
PHP
Doing private Soap reqests requires some kind of authentication. One of the most common ways is to use NTML authentication. PHP soap does not support this out of the box it. You can use this tftdias...
snippet - PHP: Download large file from url without loading it to memory
5 Dec, 2016
This snippet shows you how to download a file from url without loading it to memory. When you use file_get_contents() and file_set_contents() you load the content to memory and then to file. The...
snippet - Filename from path in PHP
22 Nov, 2016
Snippet shows you how to get filename from a path in PHP. Filename and extension separately. Can be used for extending filenames with timestamp or anything.
snippet - Select a random file from directory in PHP
22 Nov, 2016
Select a random file from directory. This can be useful if you want to display a random image on your website. For an example a background image randomly from a directory in your files.
snippet - Get body tag using PHP Dom Document
22 Sep, 2016
PHP
How to use a DOM parser and get the contents of the body.
snippet - Validate AJAX requests in Zend Framework
26 Aug, 2016
How to validate AJAX requests in Zend Framework. There is a function in request class, to use instead of comparing the $_SERVER['HTTP_X_REQUESTED_WITH'] directly. This can be beneficial for security...
snippet - Directo class
17 May, 2016
Class for fetching and sending data between directo.ee API. This class includes pulling data from Directo and posting xml with php array to xml generation.
snippet - PHP: Trim Array
5 May, 2016
PHP
This snippet shows you how to trim an array with single line of code. This can be achieved by using "array_map".
snippet - SimplePie Error: timed out after 10001 milliseconds
8 Feb, 2016
SimplePie is set to 10 seconds timeout in default. So if the feed has problem with speed then you can increase the time. The exact error that I got was "cURL error 28: Operation timed out after 10001...
snippet - PHP: Days since today or days between two dates
13 Jan, 2016
PHP
How to find out the amount of between two dates. For an example how many days have passed since a defined date.
snippet - Get every other member of array in PHP
11 Jan, 2016
PHP
Getting every other member of array in PHP. Examples of getting every other odd and even numbers.
snippet - Enable Phar in PHP 7
10 Jan, 2016
PHP
Phar is included in PHP 7 amongst other updates. It's no longer external module. You have to turn off the "readonly" parameter. Since it disables Phar write support by default.
snippet - Cache json from curl request in PHP
5 Jan, 2016
When you create a simple request without any special REST client, you can do it just by using curl. When you need to do curl request, it's not a good practise to do it on every page load. So the...
snippet - Explode multiple delimiters PHP
4 Jan, 2016
To explode multiple delimiters PHP you have to use regular expression. Add your delimiters in the parentheses separated by pipe. You might have to escape your characters if they have meaning in PCRE...
snippet - PHP: Detect delimiter of CSV file
9 Dec, 2015
PHP
Using PHP to read csv file is a common thing to do. Sadly there is no solid standard on delimiters, depends on fully from where you get your csv file. Usually simple csv exports are a bit different...
snippet - Select next as well in PhpStorm
6 Oct, 2015
PHP
Select next, is a functionality well needed in everyday programming. For an example, if you have a function that defines a variable and the variable is used multiple times. You would like to select...
snippet - PHP: Replace all whitespaces with a single space
8 Sep, 2015
You can replace all whitespaces (space, new lines, etc.) with a single space using regular expression find and replace.
written tutorial - Set PhpStorm to always show line numbers
4 Sep, 2015
PHP
PhpStorm by default does not display line numbers. Working with version control or when debugging stuff, you usually get line number of the code where the error appears. So it would make sense that...
snippet - PHP: Get values by key in multidimensional array
5 Mar, 2015
PHP
How to get values by key name in multidimensional array. You have to iterate it recursively. This is the first time I can use Iterator classes of PHP and I already can think multiple problems this...
written tutorial - PHP: Memory management
22 Feb, 2015
If you are using larger files like bigger data files or images, memory might become an issue. Even if not, it's always good practice to use optimal amount of memory. Clearing memory is just a part of...
written tutorial - Php pcre regex or operator tutorial
2 Nov, 2014
PCRE regular expression operator OR. In regular expressions "or" is known as "alternatives". Create a subgroup using parenthesis.
snippet - PHP - Replace using regex
29 Oct, 2014
Search and replace using regular expression in PHP using preg_replace function. It is very powerful way to search and replace. I suggest using some online regular expression tool to test out your...
snippet - Validate UTF-8 strings in PHP
7 May, 2014
This function checks whether a string is valid UTF-8. You can ensure that the string you operate is a valid UTF-8 string. preg_match fails on strings containing invalid UTF-8 byte sequences. It does...
snippet - Convert text or HTML to plain-text in PHP
25 Nov, 2013
Encodes special characters in a plain-text string for display as HTML. Validates strings as UTF-8, if not UTF-8 it returns an empty string. It prevents CSS attacks on IE 6.
written tutorial - Install web server (Apache, PHP, MariaDB) on Linux Debian Wheezy
20 Nov, 2013
This tutorial shows how to prepare a Debian Wheezy web server. This is just a simple setup of basic web server. I myself did it to set up a development environment for myself.
snippet - Check if text contains cyrillic characters in PHP
5 Nov, 2013
Check if text contains cyrillic characters in PHP. This example shows you how to do exactly that.
snippet - Get words in string as array in PHP
16 Sep, 2013
How to split words in string to an array using regular expressions. You can use this for search indexing for an example.
written tutorial - Read or parse feeds with PHP
7 Aug, 2013
This tutorial shows how to parse RSS feeds with PHP. From the libraries and methods that I have tested and used SimplePie is by far the best PHP RSS parser. It supports most common RSS modules out of...
snippet - Convert file size in bytes to nice (human-readable) format in PHP.
6 Aug, 2013
This snippet shows you how to convert file size in bytes to nice (human-readable) format in PHP. If the size is less than 1 MB, show the size in KB, if it's between 1 MB - 1 GB show it in MB, etc.
snippet - Get img tag image url from html using regex in PHP
25 Jul, 2013
Snippet about getting img tag image url from html using regex in PHP. Example below.
snippet - Convert time to other time zone in PHP
7 May, 2013
Convert time and date from one time zone to another in PHP.
snippet - Remove HTML elements using DOMDocument in PHP
19 Apr, 2013
This snippet shows how to remove HTML elements using DOMDocument in PHP. The problem is that you can't do it in the same loop.
written tutorial - Using DOMDocument to parse HTML in PHP
15 Apr, 2013
Sometimes you need to parse HTML with PHP. There are many different ways. It's hard to parse HTML, people write incorrect HTML very often. This code forces DOMDocument to read and later write HTML.
snippet - PHP - get extension from file name
21 Mar, 2013
Get extension from file name.
snippet - Remove width and height form img tag using PHP
29 Nov, 2012
Remove width and height attributes from img tag using PHP. Really plain and simple replace width and height attributes with nothing.
snippet - PHP range where key and value is same
2 Oct, 2012
Creating range array where key and the value is the same number. I am using array_combine function for that. I give two parameters which are the same array created by range.
snippet - PHP - strip defined tags, strip_tags reverse
9 Aug, 2012
Strip tags in PHP strips all tags, except allowed tags. This function strips tags that you define. Also you can define if you want to strip content as well.
snippet - Strip tag with class, id or anything else in PHP
23 Jul, 2012
This function strips tags by any identifier without regexp, and without heavy XML parsing. As long as the tag looks exactly the same in source-code it works.
snippet - PHP Date or Time Range
12 Jul, 2012
Iterate through date or time range using PHP.
snippet - Get MSSQL Field Data Type in PHP
29 May, 2012
Example how to get field types in MSSQL. You can use it on any query, even procedures.
snippet - Detect character encoding in PHP
26 Apr, 2012
Detect character encoding in PHP and convert string to UTF-8.
snippet - Get all MSSQL tables using PHP
17 Feb, 2012
How to get all tables names that are in a certain table.
snippet - Get MySQL tables names in PHP
14 Dec, 2011
Getting MySQL tables names in PHP.
snippet - Get MySQL column types in PHP
14 Dec, 2011
How to get MySQL columns data of a table in PHP. The data includes name, type, null allowed or not, key, default value and extra for auto_increase and such.
snippet - Check if URL is external or internal in PHP
11 Oct, 2011
Check if URL is external or internal in PHP. We are going to use parse_url PHP native function. Function parse_url parses a URL and returns an associative array containing any of the various...
snippet - Selecting from multiple tables using ActiveRecord in CodeIgniter
22 Sep, 2011
Selecting from multiple tables using ActiveRecord in CodeIgniter. Basics are the same as in query. You select multiple tables, relate tables and select the output fields.
snippet - Get PHP script execution time
22 Aug, 2011
How to test execution time of any part of the code in PHP. Basically you have to start counting microseconds before you code execution and stop after. This snippet shows how to do the counting.
snippet - Get files content type in PHP
8 Jul, 2011
This snippet gets content type of a file form external url. This snippet uses curl to download the file and get the content type.
snippet - MySQL Query Into Array in PHP
8 May, 2011
How to turn MySQL query into an array in PHP. Print query results on screen. This is useful for determining contents of a table.
snippet - Get Years in PHP
3 May, 2011
How to get current, last and coming year in PHP. Simple examples of how you can get different years. Currently the years are calculated from the server time.
written tutorial - PHP Tutorial: Add Zeros Before Number
20 Feb, 2011
This tutorial shows how to add or append zeros before numbers. You might need this if you want to make folders named by numbers and you want them to be in right order when browsing the folder with...
written tutorial - Installing Yii Framework
17 Dec, 2010
How to install and set up Yii framework application to your hosting.
written tutorial - Add Text to Image in PHP
15 Dec, 2010
PHP
This tutorial shows how you can add text to images with PHP. You can use it to make banners with dynamic content for an example.
written tutorial - How to echo or print arrays in PHP
6 Dec, 2010
Examples of parsing array values on screen. Some examples for beginners.
written tutorial - Storing Images in MySQL With PHP
12 Nov, 2010
Easy to understand tutorial on how to upload, store and display images in mysql database.
written tutorial - Create Treeview Using Recursion in PHP
9 Oct, 2010
PHP
An easy example of recursion. PHP treeview can be used to create hierarchical lists like menus including sub-menus, category trees, taxonomy trees or site maps. This tutorial shows you how to...
written tutorial - Converting CodeIgniter Query to JSON
24 Sep, 2010
This tutorial shows you how you can generate JSON from SQL data that comes from model. Converting query to JSON is really simple in PHP and even simpler in CodeIgniter.
written tutorial - CodeIgniter Login With Google Using OpenID
20 Sep, 2010
How to make login system for CodeIgniter using OpenID. This example uses Google Accounts for login.
written tutorial - CodeIgniter - Cache Any Code Into a File
19 Sep, 2010
This tutorial shows you how you can cache code in CodeIgniter, by saving string or plain text into a file.
written tutorial - Generate RSS 2.0 Feeds with CodeIgniter
22 Aug, 2010
In this tutorial we will make RSS 2.0 feeds from latest posts in your site.
written tutorial - CakePHP Routing - URL With Parameters Only
25 Jul, 2010
This tutorial shows how to do URL routing in CakePHP, if you need your URL to be without controller and view.
written tutorial - Dynamic Layout With Dynamic Menu in CakePHP
24 Jul, 2010
This tutorial shows how you can attach dynamic menu or any content to layout that you still want to call from controllers.
written tutorial - Installing CakePHP
22 Jul, 2010
This tutorial shows how to install CakePHP. After this tutorial you can start making web application.
written tutorial - PHP Global Variables
15 Jul, 2010
Tutorial about global variables in PHP. How to use global, superglobal in PHP.
written tutorial - AJAX Form Submission in CodeIgniter With jQuery
26 Jun, 2010
Some knowledge of CI and OOP could be handy. This tutorial shows how to submit Ajax forms in CodeIgniter using jQuery. With optional jQuery UI feedback bubbles.
written tutorial - Handling Timestamps in PHP
25 Jun, 2010
This tutorial is about using and converting timestamps in PHP, witch are common formats of storing some timeperiod in database.
written tutorial - Integrating WYSIWYG TinyMCE into CodeIgniter
16 Jun, 2010
This tutorial shows you how to set up WYSIWYG TinyMCE in CodeIgniter. Both versions standalone and jQuery. It's really easy, most time takes the sample code tweaking.
written tutorial - Displaying random value from array in PHP
13 Jun, 2010
This beginners tutorial shows and explains how to get random value from array in PHP.