Re: Novice question - please help

From: Date: Mon, 11 Feb 2002 21:42:52 +0000
Subject: Re: Novice question - please help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-84314@lists.php.net to get a copy of this message
Sounds like a job for regular expressions:
$bloatedString = "x   +    y";
$cleanString = preg_replace("/\s+/"," ",$bloatedString); -Steve On Monday, February 11, 2002, at 03:15 PM, brendan conroy wrote:
Hi, THANK YOU for reading this.I would really appreciate it if someone could please email me if they know any easy way or an existing function for removing an unknown ammount of space characters from an array. Iam having an awful lot of trouble trying to remove multiple space characters from an array, ie. x + y
       123456789
where there are three or more spaces in a row(rep'd above by 234 & 678), basically weird user input. I have written code already, but I cant see where Ive gone wrong, here it is if you care to look at it, and have a good chuckle, told you I was a novice! I included the start page that allows you to see what the code does, in you want to look at it. Thank you for your time, I'd really appreciate any replies! <HTML> <BODY> <? $x = 0; $ay=array(); $g=array(); $c = explode (' ', $a); for($q=0;$q<=count($c);$q++) { echo"<font color=green>"; echo"$c[$q]"; echo"<HR>"; echo"</font>"; } $c=array_reverse($c); for($w = 0;$w<count($c);$w++) { echo $w; $e=array_pop($c); if(($e == ' ')||($e == NULL)) { echo"hi space"; array_push($ay,$e); echo"<HR>"; } else { echo"hi no space"; array_push($g,$e); } } echo(count($g)); for($x=0;$x<=(count($g));$x++) { echo"<BR>"; echo"$g[$x]"; echo"<HR>"; } ?> </BODY> </HTML> ============================== start page code ====================== <html> <head> <title>npage.php</title> </head> <body bgcolor="#FFFFFF" text="#000000"> <form action="newplan2.php" method=post> enter polynomial <? echo "$i";?> here:<input type="text" name="a"> <input type="submit" name="submit" value="Submit Pols!"> </body> </html> _________________________________________________________________ Chat with friends online, try MSN Messenger: http://messenger.msn.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#84314) next »