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
https://forums.phpfreaks.com/topic/222229-getting-rid-of-whitespace/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.