Jump to content

Getting rid of whitespace.


gergy008

Recommended Posts

Okay I made this code to get the name of a file and churn it until it becomes a 5 character ID to put in the database.

 

Problem is it's not getting rid of the whitespace and I'm trying to get rid of it two different ways.

 

$tmpp1 = '/\s*/m';
$tmpr1 = '';
$tmpnm1=$filename;
$tmpnm2=preg_replace($tmpp1, $tmpr1, $tmpnm1); #Attempt number 1
$unwanted=array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U", " ");
$tmpnm3=str_replace($unwanted, "", $tmpnm2); #attempt 2!
$tmpnm4=substr($tmpnm3, 0, 5);
$tmpnm5=strtolower($tmpnm4);
$fileid=$tmpnm5;
echo($fileid);

 

If I had $filename as "I have a string and it has spaces", It turns it into " hv  " and not "hvstr" like intended.

 

And help please? Thanks in advance! :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.