Welcome, Guest

Please login or register

TUTORIALS SUBMENU

PHOTOSHOP    FLASH    ILLUSTRATOR    BLENDER    CINEMA 4D    WEB-CODING    [SUBMIT]

Related Links

Text & Number Management Functions

pages (4): [1] 2 3 4


Welcome to yet another scrowler tutorial on PHP. This tutorial covers various different text manipulation and management functions, many of which are absolutely invaluable for your scripts.

Topics that we will cover in this tutorial include:
- Text length limiting
- HTML formatting
- Replacing letters or words
- Form posted text
- Hashing strings (one way encryption, inc. mhash lib)
- Number manipulation
- Padding strings
- Converting text cases
- Word wrapping

Woah! What a list! Let’s get started then! This tutorial is written for the average PHP beginner to get a firmer grasp on the world of string management with PHP, including some basic math functions. The content of this tutorial is optimized to include web functionality i.e. stripping HTML tags from a string, converting HTML entities, etc. You will even be taught how to hash strings, going far into the mhash PHP extension library.

First up on the agenda: Text length limiting.

Text length limiting
Text length limiting is a very useful feature of PHP, and it’s relatively easy to achieve. Using inbuilt functions of PHP you can cut a string off at a certain point, and you can even check its length with a single function call!

So, let’s say that we have a submission form for a local soccer club to allow coaches to submit overviews of weekly soccer matches. The administrator doesn’t want his database to get huge, because he knows how many teams there are in the club, and he suspects that coaches might get carried away! So what does he do? The answer is simple - He imposes a text length restriction!

On Monday, the administrator is feeling rather harsh, so he decides to use substr() to simply cut everything off the string from a certain point onwards, to limit the length. He reads this tutorial and finds out the syntax for substr() is as follows: [string], [start], [length].

He checks the database and it’s huuuuuge! How can he manage to allow so much data to go in every week? Fortunately, he understands the concepts in this tutorial and is able to solve his problem in a harsh way.  Here is the code he decides to use:
 

<?php

function cutText($string)
{
$string = substr($string, 0, 5000);
return $string;
}

$string = cutText($_POST['overview']);

?>

This works successfully! If a coach inputs an overview larger than 5000 characters, anything past the 5000th character is cut off!

So the week goes by, the next soccer round commences, and a coach goes to submit his weekly overview. He loses half of it, and what does he do? He complains of course! How unfair - They didn’t even back it up!

The administrator decides to be a little nicer this time, and instead of just cutting the end off, he decides to tell the user if it’s too long, so they can cut it down to size manually. For this, he uses the function strlen() which simply takes the input argument [string] and returns its length.
 

<?php

function checkLength($string)
{
$length = strlen($string);
if($length > 5000)
{
return false;
} else {
return true;
}
}

$text = $_POST['overview'];

if(checkLength($text) == true){
# process the data
} else {
echo 'Sorry for the trouble, your data was longer than 5000 characters, could you please shorten it and retry? Thanks!';
}

?>

Problem solved! The soccer coach now has the opportunity to shorten his overview instead of completely losing the excess!  This gives us a happy administrator, as his database remains a manageable size, and happy coaches as they can submit their overviews with ease!

That concludes the section on text limiting, so let’s move on to HTML formatting!

- Tutorial written by Scrowler

Pages (4): [1] 2 3 4 Next>
Automatic Translations: Translate Into French Translate Into German Translate Into Italian Translate Into Spanish Translate Into Portuguese

Last 5 User Comments


There are no comments for this tutorial yet.
You can place a comment by clicking here.
Featured Tutorialsmore

Remote Rollovers
Remote Rollovers
- Adobe Photoshop -
Fancy Stars
Fancy Stars
- Adobe Illustrator -
DuoTones
DuoTones
- Adobe Photoshop -
Advanced Seamless ...
Advanced Seamless ...
- Adobe Photoshop -
Membership

Username:
Password:  
Remember Me

Lost Password? || Register

Related Links

Special Options
Printer Friendly Version
Forum Threads

Fire text effect in 3ds max
Author: heartscool
Posted: Jul 24th, 1:56pm
Activity: 0 replies, 0 views
Where did everyone go!?!
Author: LemonTree
Posted: Jul 22nd, 12:15am
Activity: 6 replies, 0 views
Protecting Email Addresses from Spammers in HTML
Author: LemonTree
Posted: Jul 22nd, 12:13am
Activity: 0 replies, 0 views
3ds max wireframe render ?
Author: heartscool
Posted: Jul 20th, 2:51pm
Activity: 0 replies, 0 views
Site issue
Author: Jormi_Boced
Posted: Jul 07th, 8:40pm
Activity: 11 replies, 0 views
3D Studio Max Keyboard shortcuts
Author: heartscool
Posted: Jul 07th, 6:48pm
Activity: 0 replies, 0 views
Regarding Vector/Custom Shapes in Photoshop
Author: Phoenix Wynde
Posted: Jul 06th, 1:39pm
Activity: 0 replies, 0 views
forgot a songs name
Author: unleash
Posted: Jun 30th, 10:37pm
Activity: 8 replies, 0 views
Tutorials Upload System Active
Author: Man1c M0g
Posted: Jun 28th, 11:53am
Activity: 0 replies, 0 views
Brushes Uploaded Here...
Author: Jasmine
Posted: Jun 23rd, 5:55pm
Activity: 1 replies, 0 views
Uploading Resources: Alternative Method?
Author: Jasmine
Posted: Jun 21st, 10:31pm
Activity: 1 replies, 0 views
Public Vote on Brush Contest Entries...
Author: Jasmine
Posted: Jun 17th, 12:25am
Activity: 0 replies, 0 views
Forum Threads

--- Site Resources ---
Total Tutorials:212
Total Downloads:    438
Total Fonts:    4673