PHP - Getting Rid Of Whitespace.
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! Similar Tutorials$string = " hel lo "; $string = rtrim($string); $string= ltrim($string); which trims the whitespace from the front and back, but how do i remove the middle space? Thanks Hello All: I am trying to access a value within an object. The value name has whitespace in it and is called "zip code". When I try to access the value via regular object call such as: Code: [Select] $sub = $sub->zip code; PHP goes crazy on me. I've tried to encapsulate the value name within a variable like this: Code: [Select] $zip_code = "Zip Code"; $sub = $sub->zip_code; and that doesn't work either. Does anyone have any ideas about how I should go about yanking the data out? In my php and html code I have lots of whitespace and line breaks between the <tags>. How I can remove all useless whitespace and linebreaks without altering the main text and codes? I have code: $proname1 = preg_match_all('/<div class=("|\')agentContainer("|\')>(\n\s)<div class="strong">(\n\s)(.*?)(\n\s)<\/div>/', $html, $name1);() Which is putting everything between these tags into an array, but the info contains new lines and whitespace, thus displaying empty entries in the array. How do I strip the whitespace and newlines prior to getting to the array? The data Im getting looks like... Code: [Select] <div class="agentContainer"> <div class="strong"> Blah Blah Company </div> And blah blah company isnt showing up in the array, but I know the regex is working. hello everyone.
could you advise me on the structure of my code to check if it is correct:
RewriteRule ^/user/([a-z]+)/cake/([a-z\ .*A-Zx0-9-_]+)$ /cakes.php?userid=$1&cakebaked=$2what i am trying to do is to add a - instead of a whitespace which appears in the url as %20. Hi all I need to remove the spaces in an uploaded file. I have tried str_replace and trim etc... but it doesn't work. Here is my code: Code: [Select] move_uploaded_file($_FILES['image']['tmp_name'][$i], WEB_UPLOAD."/images/galleries/g".$gid."/".$_FILES['image']['name'][$i]) or die("Error uploading image "); Thanks Pete How am i to do this either a php builtin function i am unaware about or something simple with regular expressions replacing I need a way to remove whitespace (tabs,spaces,newlines,etc) and anything else that seperates <> tags such as Code: [Select] <td class="subject solvedbg"> <div> <span id="msg_1">blah blah space see <a href="blahblah> </div> </td> to Code: [Select] <td class="subject solvedbg"><div><span id="msg_1">blah blah space see<a href="blahblah></div></td> Thank you. |