PHP How to include variable inside echo
This is a very simple example of how to include a variable inside a PHP echo. <?php $a = "1234"; echo "This is a number: ".$a; ?> 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 $a = "this is a sentence"; if (strlen($a) > 10) { echo $a; } ?>
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 $a "this is a sentence" $a = str_replace("\t",' ',$a); echo $a; ?> The [...]
PHP Str Replace
str_replace is a very simple PHP function. It replaces chosen characters in a string. $a = “this is a sentence”; $b = str_replace(” “, ‘_’, $a); echo $b; 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. $a = array(“orange”, “purple”, “red”, “blue”); $clean = Array(); $blacklist = ‘/(oranges|red)/’; foreach($a as $b) { if(!preg_match($blacklist, $b)) { $clean[] = $b; } }
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… include (‘yourFile.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 $a = 'this is a sentence'; if (strpos($a,'this') !== false) { echo 'true'; } ?>
Pure CSS3 Dropdown Menu
Forget Javascript… It’s all about CSS3 The days of having to use bloated Javascript for the most simple of dropdown menus are over!! Though this is a very simple example, with no fancy effects it does the job and in my opinion looks better than a fading or sliding dropdown menu. The whole of this [...]
Dynamically Load Content Using jQuery
One thing that we have started to use a lot, especially with bigger database driven sites is the jQuery load() selector. This handy little function makes it really easy to dynamically load content when a user performs an action. Meaning that the content will not be visible/present when the page loads and jQuery will load [...]
Simple AJAX Contact Form
We have been very busy with various projects recently, so have not had much time to post any guides recently. We have had a few people ask recently how they would make an AJAX contact form, so we thought we would write a post and tell everyone how it’s done. This contact form also includes [...]