PHP Snippets - Words

PHP Snippets for manipulating strings, words and characters

Capitalize The First Letter Of Words

To display the first letter of words in uppercase. This can be useful when displaying the title of a page.

Usage:

echo ucwords("the words i want to display in uppercase"); or $words = "the words i want to display in uppercase"; echo ucwords($words);

Result:

The Words I Want To Display In Uppercase

Replace Characters In A String, And More

Let's say you wanted to replace all spaces with commas.

Usage:

$string = 'I,sure,wish,these,commas,would,go,away'; echo str_replace(',', ' ', $string);

Result:

I sure wish these commas would go away
Or maybe remove the .php extension from the end of a URL

Usage:

$string = 'http://website.com/hide.php'; echo str_replace('.php', '', $string);

Result:

http://website.com/hide

Remove Everything Beginning With The Last Slash At The End Of A URL

Sometimes you may need to remove the trailing section of a website address.

Usage:

$link = "http://website.com/with/page.php?query=wedontwant"; echo substr($link, 0, strrpos( $link, '/'));

Result:

http://website.com/with

First Column

Nunc quis varius odio. In sed augue velit. Nunc vel auctor velit, vitae ultrices nunc. Nullam sed dui bibendum nunc luctus pharetra non eu nisl. Phasellus neque urna, semper at ultricies in, tempus tincidunt magna. Phasellus tempor posuere nulla, vel tincidunt dolor iaculis sodales. Suspendisse dapibus ipsum non nibh fermentum, quis gravida mauris tempor. Proin ultrices metus vitae congue vestibulum. Aenean et dui ac lorem consequat hendrerit. Suspendisse fermentum pellentesque velit sed lacinia. Curabitur ultrices purus lorem, mattis cursus ipsum cursus nec.

Second Column

Nunc quis varius odio. In sed augue velit. Nunc vel auctor velit, vitae ultrices nunc. Nullam sed dui bibendum nunc luctus pharetra non eu nisl. Phasellus neque urna, semper at ultricies in, tempus tincidunt magna. Phasellus tempor posuere nulla, vel tincidunt dolor iaculis sodales. Suspendisse dapibus ipsum non nibh fermentum, quis gravida mauris tempor. Proin ultrices metus vitae congue vestibulum. Aenean et dui ac lorem consequat hendrerit. Suspendisse fermentum pellentesque velit sed lacinia. Curabitur ultrices purus lorem, mattis cursus ipsum cursus nec.

Sticky Side Column

If you're using our PHP Website Template, this is the optional side bar column you can add to some or all of your pages. It can be useful for adding advertisements such as Adsense ads to be displayed on multiple pages.
When you include the side column, your main content will automatically adjust its width to accommodate it.
The side bar is 'sticky'; it will scroll down and remain in view.
You can turn on/off the side bar column per page by defining the $showSide option located at the top of each file.