PDA

View Full Version : Telling the difference between space bar and return key


ap0c
07-16-2004, 01:46 AM
$_POST['xtraimg'] = trim(preg_replace('#\s+#si', ' ', $_POST['xtraimg']));


The above code strips all spaces completely out, only leaving one like it should.
However it removes spaces for paragraphs also. Is there a way a code can tell the difference between a spacebar space and a return/enter key newline/space?

ap0c
07-16-2004, 01:49 AM
code looks better now

Modin
07-16-2004, 04:54 AM
you can probably use a class of characters instead of \s if you don't want \n (newline) to be matched.

try using [\x20] instead of \s if you just want to match spaces.

so, your code would look like

$_POST['xtraimg'] = trim(preg_replace('#[\x20]+#si', ' ', $_POST['xtraimg']));

ap0c
07-16-2004, 01:50 PM
cool, thanks
I'll give it a shot!

edit:
I found a use for this in vb also

Modin
07-19-2004, 12:12 AM
heh, relooking at my code... you don't need the braces ['s ]'s

\x20+ will work just fine too... don't know what I was thinking ;)