vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Telling the difference between space bar and return key (https://vborg.vbsupport.ru/showthread.php?t=67228)

ap0c 07-16-2004 01:46 AM

Telling the difference between space bar and return key
 
Code:

$_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

Code:

$_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 ;)


All times are GMT. The time now is 09:13 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01008 seconds
  • Memory Usage 1,708KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete