Php: format decimal numbers
Jun 26, 2010 Basic PHP
Say you need to set the priority of an XML sitemap, and you want it to be nicely formatted as a decimal number between 0 and 1.
Of course you need to print out numbers such as 0.6, maybe for an important but not critical section, or 0.2 for that privacy policy you update only when…………….
Read Php: format decimal numbers »
Tags: format decimal numbers, how to format decimal places in php, limit decimal places in php, php decimal formatting, php float decimal places, php format number currency, php xlm sitemap priority
Remove item from array remove null values
Sep 11, 2009 Basic PHP
Say we want to drop a value from an array, this is simple: just unset it!
unset($myarray[13]);
Sometimes however we may want to perform some more complex clean ups. Such as if we have just exploded an URL for url rewriting, and want to get rid of the null array items placed where the slashes were.
First approach…………….
Read Remove item from array remove null values »
Tags: php array, php array values, php optimization, php performance
International characters in PHP
Aug 11, 2009 Basic PHP
Your feed displays funky characters? European accents turn into a mess? Properly encoding UTF8 characters is the solution.
Read International characters in PHP »
Tags: php function, utf8
PHP Tutorial : Write to a file with fwrite
Jun 11, 2009 Basic PHP
I showed you earlier in a older post how to open and read text contents from a file. Now it’s time to see how to write to a file using php function called fwrite().
<?php
$theFileToWriteTo = “textFile.txt”;
$fileHandle = fopen($theFileToWriteTo, ‘w’) or die(“cannot open the text file”);
$textToWrite = “First text to write here\n”;
fwrite($fileHandle, $textToWrite);
$textToWrite = “Second line…………….
Read PHP Tutorial : Write to a file with fwrite »
Tags: file handle, fwrite, php file handle, php fwrite, php write to a file
PHP Tutorial : Multiple string replace with str_replace
Jun 10, 2009 Basic PHP
Well, I already writed about str_replace php function but this tip is very usefull. To recap, the function it’s used to replace a string by using three paramaters : $stringToSearch, $stringToReplace, $intoString. I showed you how to use it in single operations but we can use it for multiple replaces in one place, by using…………….
Read PHP Tutorial : Multiple string replace with str_replace »
Tags: php multi str_replace, php multiple string replace, php multiple str_replace, php string replace, php str_replace, string replace, str_replace
PHP Tutorial : Strpos and Strrpos
Jun 9, 2009 Basic PHP
Basic thing, strpos and strrpos are two php functions which are used to find the position of first and/or last occurrence in a string – word (usefull for example when you want to build a function to get file extension). I hear you saying enough talking, let me see the available examples :
<?php
//get first occurrence
$string…………….
Read PHP Tutorial : Strpos and Strrpos »
Tags: Find position of first occurrence of a string, occurrence, position, strpos, strrpos
PHP Tutorial : String lenght with strlen
May 26, 2009 Basic PHP
I’ll be directly on this short one. Shame on me that I didn’t writed about this untill now : there’s an interesting php function which you might need frequently called strlen() which translates into string lenght. I’m sure you met it already into previous tutorials on this php tutorials blog but I think I didn’t…………….
Read PHP Tutorial : String lenght with strlen »
Tags: php count characters, php count digits, php string lenght, php strlen, string lenght, strlen
PHP Tutorial : If condition in the short way (shorthand if)
May 21, 2009 Basic PHP
Do you know basical php if() condition right? Yeah, right. Everybody does. To tell the truth, without a comparison operator a language would not be qualified as “programming language” (that’s why HTML is a markup language and not a programming language: it can not do comparisons and alter the program flow according to their results).
But…………….
Read PHP Tutorial : If condition in the short way (shorthand if) »
Tags: if, if condition, if function, php if, php ternary comparison, php ternary operator, short if, shorthand if
PHP Tutorial : PHP $_POST array
Apr 12, 2009 Basic PHP
Hello folks,
BTW Happy Easter,my traffic this weekend decreased dramatically because of the hollidays, I hope you enjoy it.
I want to clarify something that I might missed to say about php $_POST : this $_POST is an php array, if you want to see yourself, make recursive print with print_r() function. For example if you have…………….
Read PHP Tutorial : PHP $_POST array »
Tags: $_POST array, php $_POST, php $_POST array
PHP Tutorial : Substract part of string with substr
Apr 10, 2009 Basic PHP
Hello,
I didn’t posted for a long time because I am simply stucked into finding a subject. I made a search into my own blog and I saw that (miraculous btw) I didn’t writed yet about substr function which helps you to print only a part of a string – substract it!
<?php
$stringIs = “mystring”;
$substract = substr($stringIs,…………….
Read PHP Tutorial : Substract part of string with substr »
Tags: php part of a string, php substr, php substract part of a string, substr

