?
Solved

Making string contents short and simple

Posted on 2005-03-14
2
Medium Priority
?
280 Views
Last Modified: 2006-11-17
Hello.

How can I get rid of all non alphanumeric characters in a string, AND cut the string so that it is no longer than 10 characters?

So that:
   "123... This is a test & only a test!"

becomes:
   "123Thisisa"

Thanks!
0
Comment
Question by:hankknight
2 Comments
 
LVL 10

Assisted Solution

by:eeBlueShadow
eeBlueShadow earned 444 total points
ID: 13536100
$str = "123... This is a test & only a test!"

$str = preg_replace('|\W|', '', $str);
$str = substr($str, 0, 10);
0
 
LVL 32

Accepted Solution

by:
Batalf earned 888 total points
ID: 13536104
$string = "123... This is a test & only a test!";
$string = substr(preg_replace("/[^a-zA-Z0-9]/si","",$string),0,10);
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question