Php: format decimal numbers

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 »

Remove item from array remove null values

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 »

International characters in PHP

Your feed displays funky characters? European accents turn into a mess? Properly encoding UTF8 characters is the solution.

Read International characters in PHP »

PHP Tutorial : Write to a file with fwrite

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 »

PHP Tutorial : Multiple string replace with str_replace

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 »

PHP Tutorial : Strpos and Strrpos

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 »

PHP Tutorial : String lenght with strlen

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 »

PHP Tutorial : If condition in the short way (shorthand if)

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) »

PHP Tutorial : PHP $_POST array

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 »

PHP Tutorial : Substract part of string with substr

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 »