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! Link to comment https://forums.phpfreaks.com/topic/222229-getting-rid-of-whitespace/ Share on other sites More sharing options...
Rifts Posted December 20, 2010 Share Posted December 20, 2010 trim() Link to comment https://forums.phpfreaks.com/topic/222229-getting-rid-of-whitespace/#findComment-1149599 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); ?> Link to comment https://forums.phpfreaks.com/topic/222229-getting-rid-of-whitespace/#findComment-1149601 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.