php - Should running preg_replace twice break a WAMP connection? -


i trying replace text in string using preg_replace. now, maybe not doing correctly, running once, doesn't trick trying replace overlapping strings. when run preg_replace once, works fine (minus half of text way want). when try run twice bad connection error in both chrome , ie (so isn't browser issue, not thought be) @ least wamp (i haven't tried on real server).

so, there wrong with:

1) php logic,

2) regex,

3) or preg_replace , wamp?

i want separate (put spaces between) of numbers have following format: 0.xx

$text = "0.450.590.88 aut 0.570.210.400.89 cus 0.630.310.370.440.87 del 0.580.130.310.570.450.89 eva 0.600.230.420.550.440.650.91 int 0.590.390.620.530.540.520.560.85 iop 0.480.240.440.440.440.550.580.600.88 mon 0.690.390.480.560.640.610.610.550.520.85";   ($i=0;$i<2;$i++)     $text = preg_replace('#0\.(\d{1,4})0\.#', '0.${1} 0.', $text); 

i want $text result in:

0.45 0.59 0.88 aut 0.57 0.21 0.40 0.89 cus 0.63 0.31 0.37 0.44 0.87 del 0.58 0.13 0.31 0.57 0.45 0.89 eva 0.60 0.23 0.42 0.55 0.44 0.65 0.91 int 0.59 0.39 0.62 0.53 0.54 0.52 0.56 0.85 iop 0.48 0.24 0.44 0.44 0.44 0.55 0.58 0.60 0.88 mon 0.69 0.39 0.48 0.56 0.64 0.61 0.61 0.55 0.52 0.85 

if change loop run once or if shorten text, php runs fine.

as part of larger text, don't want stick these array, want them formatted better. piece of background information text comes correlation table in pdf has had text extract, white space has not been preserved.

i don't know relation between preg_replace , server crash, can in 1 step without loop:

$result = preg_replace('~(?<=[0-9])(?=0\.[0-9]{1,4})~', ' ', $text); 

overlapping problems avoided since pattern use lookarounds determine space position.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -