0

I have an string e.g.:

src="http://www.domain.com/sub_folder/xyz_17215_andso_on_01-file_08.html"

and want to split this at every character that is not a letter or number.

With

/[a-z0-9]/

I get an array with all the characters but what's the opposite of it to get all the words and numbers?

netS
  • 50
  • 1
  • 7
  • 1
    you may like [parse_url()](http://www.php.net/manual/en/function.parse-url.php) – zb' Nov 24 '12 at 00:23

2 Answers2

2

You can write:

$result_array = preg_split('/[^a-z0-9]+/', $string_to_split);
ruakh
  • 175,680
  • 26
  • 273
  • 307
  • So simple... I tried this, too but with the ^ outside the []. I think I will never learn this regular expressions. Thank you. :) – netS Nov 24 '12 at 00:35
  • @netS: You're welcome! Regarding `^`: `[^...]` means "any character other than `...`. But outside `[...]`, `^` means "start of string" (or sometimes "start of line"). – ruakh Nov 24 '12 at 01:00
1

Rather than writing new code to solve a problem, use the built-in functionality that PHP provides to you in the parse_url() function: http://php.net/manual/en/function.parse-url.php

Andy Lester
  • 91,102
  • 13
  • 100
  • 152