Follow us on Twitter Like us on Facebook
Web Design Agency in Portsmouth

PHP How to include variable inside echo

This is a very simple example of how to include a variable inside a PHP echo. [php] [/php] The dot after the speech mark connects the variable to the echo.

PHP How to Check if a String is Longer than

The below code uses strlen to show you how to check if a string is above 10 characters long. [php] [/php]

PHP How to remove/replace tab in string

From past experience I have found that if you copy and paste content form Microsoft Word of from webpages, there can sometimes be tab characters within the text. To remove tab characters in your PHP string you can do the following… [php] [/php] The above code uses str_replace to replace the tab character with a [...]

PHP Str Replace

str_replace is a very simple PHP function. It replaces chosen characters in a string. [php] $a = “this is a sentence”; $b = str_replace(” “, ‘_’, $a); echo $b; [/php] The above code will replace all the spaces in the sentence with underscores.

Blacklist words in PHP Array

The following code can be used to not display php array results that contain certain “blacklisted” words. [php] $a = array(“orange”, “purple”, “red”, “blue”); $clean = Array(); $blacklist = ‘/(oranges|red)/’; foreach($a as $b) { if(!preg_match($blacklist, $b)) { $clean[] = $b; } } [/php]

How to do a PHP include

A PHP include simply includes the source from another file. It can be useful for website headers/footers, saving PHP variables and/or settings and many other purposes. All you need is this… [php] include (‘yourFile.php’); [/php]

PHP – How to check if a string/sentence contains specific word

The below code is an if statement to check if a string/sentence contains a specific word. [php] [/php]