Language Archives

How to strip off last two characters from string using substr

substr comes in handy if you need to strip characters off the end of a string.

<?php
$test_string = ‘item 1, item 2, item 3, ‘;
$test_string = substr($test_string,0,-2);
echo($test_string); // returns “item 1, item 2, item 3″
?>

PHP Hello world!

Welcome to the PHP-scripts blog. Though I’m not a huge fan of ‘Hello World’ stuff, it seems that is where most things in the programming world start out. So here we go with examples using print and echo
Hello World using print statement

<?php
print ‘Hello World!’;
?>

Hello World using echo

<?php
echo ‘Hello World!’;
?>

What is the difference between […]