Author Archives: Andrei
How to save image from URL using PHP
How to save image from URL using PHP You have an image in a URL, something like “http://www.yourhowto.net/wp-content/uploads/2012/09/mysql-java-jdbc1.jpg“, and you want to save that image in your computer, but you want to obtain that directly from PHP. You can use 2 methods for this, one is using CURL and one using fopen directly. First method
How to remove the last character in a string in PHP ?
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
1 2 3 |
$string = "1,2,3,4,5,6,7,8,"; $newString = rtrim($string, ","); echo $newString; //outputs "1,2,3,4,5,6,7,8" as a string |
1 2 3 |
$string = "1,2,3,4,5,6,7,8,"; $newString = trim($string, ","); echo $newString; //outputs "1,2,3,4,5,6,7,8" as a string |
2nd
PHP math operations and operators
PHP math operations and operators PHP is a very powerful language that can help you to perform mathematical operations really easy. Math expressions are made up of operators and operands. You can perform easy operations like adding, subtracting, multiplying or dividing with PHP. Even comparison operators can be used with this language (greater than, less
Convert variable to string in PHP
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