Click to See Complete Forum and Search --> : [RESOLVED] using Regular Expressions to match blankness.


Kyleva2204
09-04-2008, 05:58 PM
Ok, so maybe this can be done with out regular expressions but explode() does not work.. Here is my problem.. I have a string like so:

/one/2//3/4//5///b/

and I want to be able to match everything in between the slashes.. wether it have content or not. I have tried explode('/',$my_string); but not only does that ignore the blanks, but it also makes an extra array item if it has the ending /. I have tried using regular expressions and preg_match_all, but with no real luck. I could easily get it to match ending the ending slash or not (it won't always be there).. I just need some help getting my expression to match the blank lines..

Heres what I have tried, any help would be great :).

preg_match_all('!(.*|^$)/!U',$string,$array);


On second thought, if someone could help me try and get it to work with or without the ending slash, that would be cool too :).

NogDog
09-04-2008, 06:10 PM
Is this what you're after?

<?php
$test = '/one/2//3/4//5///b/';
$fields = explode('/', trim($test, '/'));
echo "<pre>".print_r($fields,1)."</pre>";

Outputs:

Array
(
[0] => one
[1] => 2
[2] =>
[3] => 3
[4] => 4
[5] =>
[6] => 5
[7] =>
[8] =>
[9] => b
)

Kyleva2204
09-04-2008, 06:29 PM
Ok, yes. But I just noticed it wasn't a problem with my explode (including blanks).. My whole idea is to send a url like this:
mysite.com/stuff/asdf/asdf/asdf//fff/
to a rewrite rule and send everything after /stuff/ as a $_GET['url'];... and it was Apache that was excluding the blanks.. even though I have NO real specific find, just any character after /stuff/.

RewriteRule ^stuff/(.*)$ ./index.php?stuff=$1 [NC,L]

I know this isn't the place to ask, but any ideas?