vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Stripping whitespace between commas? (https://vborg.vbsupport.ru/showthread.php?t=262620)

Boofo 04-25-2011 02:37 PM

Stripping whitespace between commas?
 
Does anyone know how I can make the following pre_replace also strips out whitespace BETWEEN the commas?

Right now it will trim the elements of any whitespace that may come before or after the comma. But, say, I have this:

Code:

2    4  ,    3        ,    1      1

It won't strip out the space between the 2 and the 4, or the 1 and the 1.

Code:

$str = trim(preg_replace('|\\s*(?:' . preg_quote($delimiter) . ')\\s*|', $delimiter, $str));

Disasterpiece 04-26-2011 08:41 AM

PHP Code:

$tmparray explode(",",$array);
array_map("trim",$tmparray);
$array implode(",",$tmparray); 

PHP Code:

$str str_replace(" \t\r\n","",$str); 

pick one

(not tested)

Boofo 04-26-2011 08:30 PM

I meant how to add that ability to the pre_replace line I posted, so it does that also. I know how to do it by itself.

Also, your second one doesn't work for spaces. This does:

PHP Code:

$str str_replace(" ","",$str); 


Now, it there any way to get the preg_replace to do that also between the commas? Right now it only works on spaces before and after the commas themselves.

cosmicsea 04-26-2011 11:37 PM

If you would like pretty much instant answer on this go ask it on stackoverflow. I use it all the time and I always get my problems solved within 15 to 20 minutes if not sooner. Just a suggestion.

Boofo 04-26-2011 11:42 PM

I was hoping someone here might have an answer, too. ;)

I just asked on there so we will see what happens. Thanks for the tip.


All times are GMT. The time now is 10:25 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.01060 seconds
  • Memory Usage 1,720KB
  • 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
  • (3)bbcode_php_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