Re: formatting form information
| From: | Steve Edberg | Date: | Fri, 04 Aug 2000 23:27:11 +0000 |
| Subject: | Re: formatting form information | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-10213@lists.php.net to get a copy of this message | ||
At 4:19 PM -0400 8/4/00, Kevin Beckford wrote:
yes - read the manual on explode... ----- Original Message ----- From: Craig Henderson <craigh@mail.ocis.net> To: <php-general@lists.php.net> Sent: Friday, August 04, 2000 4:01 PM Subject: [PHP] formatting form information Hello, I'm kind of a newbie with PHP, I've been working with it for about 3 weeks now, using it on some of the sites I have been putting up, however I am not too familiar with it yet. I have a customer who wants the user to be able to post an online add in a text box, and depending on how many words it is they will charge a different value. So I was thinking I could just use the explode() function to split apart the words and then count the number of elements in the array. However can explode() work with the space character? If this isn't clear let me know and I will try to re-phrase, thanks in advance for anyone who replies. --Craig Henderson MBM Webcraft/Adgrafix Webhosting ServicesTo add my 2 cents - explode() will indeed work with spaces, but you won't get an accurate count if the person uses multiple spaces, tabs or carriage returns. You might want to try the split() function - which also returns an array - with a regular expression. For example: $WordArray = split('[[:space:]]+', $AdText); There's also a preg_split() function, if you like perl-style: $WordArray = preg_split('/[\s]+/, $AdText); Of course, you might want to split things on punctuation as well: $WordArray = split('[^[:alnum:]]+', $AdText); (that splits on any string on 1 or more characters that ISN'T a letter or number) or $WordArray = preg_split('/[\W]+/, $AdText); ([\W], as I recall, being equivalent to non-word characters, and equivalent to [^\w]). Of course you could also split on spaces and SELECTED punctuation, such as: $WordArray = split('[[:space:],;.]+', $AdText); The possibilities are endless! -steve +--- "They've got a cherry pie there, that'll kill ya" ------------------+
| Steve Edberg University of California, Davis | | sbedberg@ucdavis.edu Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ |+-------------------------------------- FBI Special Agent Dale Cooper ---+