gergy008 Posted December 20, 2010 Share Posted December 20, 2010 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! Quote Link to comment Share on other sites More sharing options...
Rifts Posted December 20, 2010 Share Posted December 20, 2010 trim() Quote Link to comment Share on other sites More sharing options...
johnny86 Posted December 20, 2010 Share Posted December 20, 2010 <?php $str = "I have a string and it has spaces"; $str = preg_replace("#[aeiouy\s]+#i", "", $str); echo substr($str, 0, 5); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.