Programming Archives - Page 2 of 9 - Ian Carnaghan

How to remove duplicate values in a PHP array

Use the array_unique function array_unique (PHP 4 >= 4.0.1, PHP 5) array_unique (Takes an input array and returns a new array without duplicate...

Mar 22 · 20 sec read >

How to embed images using PHPMailer

Use the AddEmbeddedImage method provided by the PHPMailer class. eg. $mail->AddEmbeddedImage(‘test.gif’,’testImage’,’test.gif’); Parameters for AddEmbeddedImage($path, $cid, $name = ”, $encoding = ‘base64’, $type = ‘application/octet-stream’) $path = Path...

Mar 22 · 28 sec read >

How to solve error: ‘PHP Warning: DOMDocument::createElement(): unterminated entity reference’ when creating a new element using the DOMDocument object model

DOMDocument = Represents an entire HTML or XML document; serves as the root of the document tree.  (PHP 5) DOMDocument::createElement()  = Create new...

Mar 22 · 13 sec read >

How to remove values in one array from another array using PHP

Example: I have array A with values and another array B. I need to remove the values in array A from the values in...

Mar 22 · 30 sec read >

How to check which version of PHP you are running on Linux

NOTE: Tested on Centos 4 & 5 and Ubuntu 9.04 In the command line type in the following command...

Mar 22 · 9 sec read >

How to display code as content using PHP as your programming language

I have the following JavaScript code that I need to display as plain content on a page and when I add...

Mar 22 · 26 sec read >

How to remove the first element of an array using PHP and then storing the element in a variable

By using the PHP function ‘array_shift‘ we can remove the first value of an array array_shift – Shift an element off...

Mar 22 · 29 sec read >

How to force a CSV file to download when clicking on a download link using PHP

Example: We have a CSV file called example.csv we want users to download to use as a template. Now some browsers will display the contents of the...

Mar 22 · 42 sec read >

How to convert all $_POST or $_GET values to Integers

By using the built-in PHP functions  array_map and intval. array_map = Applies the callback to the elements of the given arrays, this applies...

Mar 22 · 16 sec read >