content top

Shorten Paragraph or String without broken/incomplete word using PHP up to a maximum character length

Shorten Paragraph or String without broken/incomplete word using PHP up to a maximum character length

Ever wondered how to shorten a paragraph or string using PHP without broken words? There is a function in PHP substr() which cops a string upto a character length. But the problem is, that it leaves incomplete words after shortening. Say you have a paragraph: The famous astrophysicist, speaking in a new documentary, said spaceships could one day be capable of such high speeds that time slowed down for those on board. According to the Times...

Read More

Get Parent directory of Current URL using PHP dirname function

Suppose you are at a URL http://yoursite.domain/dir1/subdir2/subdir/file.php and want to get the 1st level Parent directory of this URL. Evidently, the URL of the parent Directory will be http://yoursite.domain/dir1/subdir2/subdir but the question is how to generate it automatically using PHP. The answer is using PHP function dirname(). Using this, you can easily get any level of parent directories of the current URL. Before you check the...

Read More

Create Login Admin & Logout Page in PHP w/ SESSION n MySQL

This post has been outdated. Please check the new one here where we have discussed how to create the system using session and cookie with remember me option. In this tutorial we shall see, how to create a basic Login System in PHP using SESSION. We shall discuss, a fully secured login system with MySQL connectivity along with an Online Demo. The login system will redirect access to the admin file if not logged in! It will also show...

Read More

How to break a foreach loop in PHP after a certain number

Just a few days back, one of my friend asked me how to break a foreach loop in PHP after a certain number of looping. Well, foreach loop is basically the for loop for arrays. It loops until it reaches the end of the array and keeps on executing the block for each of the array content. So, it is named as foreach Loop. This is the basic structure of a foreach loop in PHP: <?php foreach($my_array as $key => $value) { //Code to...

Read More
Page 2 of 212
content top
TOP