带有正则表达式的preg_split url

时间:2020-12-04 22:08:47

I have an string e.g.:

我有一个字符串例如:

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

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?

我得到了一个包含所有字符的数组但是它与获取所有单词和数字相反的是什么?

2 个解决方案

#1


2  

You can write:

你可以写:

$result_array = preg_split('/[^a-z0-9]+/', $string_to_split);

#2


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

而不是编写新代码来解决问题,而是使用PHP在parse_url()函数中为您提供的内置功能:http://php.net/manual/en/function.parse-url.php

#1


2  

You can write:

你可以写:

$result_array = preg_split('/[^a-z0-9]+/', $string_to_split);

#2


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

而不是编写新代码来解决问题,而是使用PHP在parse_url()函数中为您提供的内置功能:http://php.net/manual/en/function.parse-url.php