preg_split() is a PHP function which allows splitting a string using a regular expression.
Questions tagged [preg-split]
550 questions
-1
votes
1 answer
How do I rewrite split() to preg_split()
Here is my code that I want to update from 5.1 to 5.3 in php
$filename=$_FILES['file']['name'];
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];…

Cup of Java
- 1,769
- 2
- 21
- 34
-1
votes
2 answers
PHP Slipt Text and assign to an Array
I am trying to split and assign the values into an array for a text like this:
Title: Wonderful World
----
Text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed facilisis nulla dui, etiaculis enim porta aliquet.
Etiam ante mauris,…

user702300
- 1,211
- 5
- 22
- 32
-1
votes
3 answers
preg_split regex on different characters
I am trying to split up some titles into 3 parts:
Title: Name -- Edition
I'd like to split up these strings into
Array
(
[0] => Title
[1] => Name
[2] => Edition
)
These titles may not have the edition, or the name field, or either of…

Corey
- 815
- 3
- 13
- 21
-1
votes
2 answers
Splitting GET string
I need to split my GET string into some array. The string looks like this:
ident[0]=&value[0]=&version[0]=&....&ident[N]=&value[N]=&version[N]=
So, I need to split this string by every third…

Oles Kashchenko
- 27
- 5
-1
votes
2 answers
preg_split for email pattern
$email_address_pattern="([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,6}";
$address= "abc@gmail.com";
$length=strlen($address);
for($position=0;$position<$length;) {
…
-1
votes
2 answers
Match words starting with capitals in php?
I have a string
$str="NassarWellerGomez-GarciaSanchez-RenedoLoeches-SanchezGomez-GarciaMunoz-FerrerasSanchez-RenedoChiaoHakkarainenWernerValkamaHarounPlett";
I want to match words starting with capitals only like:
Nassar
Weller
Gomez-Garcia etc
I…

Aditya
- 4,453
- 3
- 28
- 39
-1
votes
1 answer
RegExp to get lines with linebreaks
I'm trying to get some comment lines out of our database, they are stored as a string, separated by '\n'. Unfortunately in some of the comments contain texts - also with '\n', and I don't get them separated accordingly.
An example comment looks…

manuxi
- 353
- 5
- 12
-2
votes
1 answer
Split string with PHP piece by piece
I have a string that I want to split like this:
Sinn.und.Sinnlichkeit.1995.German.DL.1080p.BluRay.x264-RSG <--- Original string
Sinn.und.Sinnlichkeit.1995.German.DL.1080p.BluRay.x264 <--- no match
Sinn.und.Sinnlichkeit.1995.German.DL.1080p.BluRay…

Daniel
- 11
- 3
-2
votes
2 answers
How to parse a mostly consistent filename into meaningful parts?
I have filenames like:
1234_56_78 A_FAIRLY_SHORT_TITLE_D.pdf
Luckily, the file naming is pretty consistent, but I can't absolutely guarantee that someone didn't use a space where they should have used an underscore.
With this in mind, I want to…

Strawberry
- 33,750
- 13
- 40
- 57
-2
votes
1 answer
Split/Explode a string in PHP
I need to split or explode a string.
K1123-Food, Apple, Z3456-Egg, Mushroom, M9902-Plant, Soil, Water, Q8876-Medicine, Car, Splitter
into something like
K1123-Food, Apple
Z3456-Egg, Mushroom
M9902-Plant, Soil, Water
Q8876-Medicine, Car,…

davykiash
- 1,796
- 5
- 27
- 60
-2
votes
3 answers
Split string into hashtagged words and non-hashtagged phrases
How can I split this string:
#now my time #Cairo travel #here
to become an array like this:
Array (
[0] => #now
[1] => my time
[2] => #Cairo
[3] => travel
[4] => #here
)
All words starting with a hash symbol can only be one word…

M.Ahmed
- 67
- 1
- 9
-2
votes
6 answers
Regex to split string into array of numbers and characters using PHP
I have an arithmetic string that will be similar to the following pattern.
a. 1+2+3
b. 2/1*100
c. 1+2+3/3*100
d. (1*2)/(3*4)*100
Points to note are that
1. the string will never contain spaces.
2. the string will always be a…

Chaitra Hegde
- 39
- 5
-2
votes
2 answers
How to split string into an alphabetic string and a numeric string?
I need to use preg_split() function to split string into alpha and numeric.
Ex: ABC10000 into, ABC and 10000
GSQ39800 into GSQ and 39800
WERTYI67888 into WERTYI and 67888
Alpha characters will be the first characters(any number of) of the string…

Shaolin
- 2,541
- 4
- 30
- 41
-2
votes
2 answers
PHP split string on word before colon
I have a string that looks like this:
aaaaa: lorem ipsum bb: dolor sit amet ccc: no pro movet
What would be the best way to split the string into an array and get the following result in PHP?
array[0]='aaaaa: lorem ipsum';
array[1]='bb: dolor sit…

johnohod
- 494
- 5
- 19
-2
votes
1 answer
How to capture all numbers outside of parentheses?
If I have a string like this:
$string = "number: 20 (10 30 10 zzz) 40 60";
How do I match all numbers outside the parentheses?
I would like to get only
20,40,60

SahebSoft
- 31
- 7