preg_split() is a PHP function which allows splitting a string using a regular expression.
Questions tagged [preg-split]
550 questions
0
votes
2 answers
Cutting string by first number found
I have to cut the first part of my string before any number found. For example:
string: "BOBOSZ 27A lok.6" should be cutted to 'BOBOSZ "
string: "aaa 43543" should be cutted to "aaa "
string: "aa2bhs2" should be cutted to "aa"
Im trying with…

Michal Olszowski
- 795
- 1
- 8
- 25
0
votes
1 answer
Using preg_split on alpha-numeric string in PHP
Consider the string 12345aaa. I want to use preg_split() on it so only the numeric part of it will be returned (i.e. 12345). How would I write the regex for it ?

Valentin Flachsel
- 10,795
- 10
- 44
- 67
0
votes
2 answers
How can I split a string into LETTERS and FLOAT/INTEGER numbers
I've been trying for the couple of days to split a string into letters and numbers. I've found various solutions but they do not work up to my expectations (some of them only separate letters from digits (not integers or float numbers/per say…

Crys Ex
- 335
- 1
- 4
- 9
0
votes
3 answers
Split a sentence into parts based on punctuation
I have spent the last hour looking for replies but I haven't found any yet, so here I ask...
I need a way (certainly regex, but everything else like explode is fine) to cut a sentence like the following into parts, in the same array:
This is the…

Julien
- 27
- 7
0
votes
2 answers
php regular expression for new line and spaces
i have a string like below:
صفحه نخست - خبرآنلاین
شنبه 20 مهر 1392 - 04:18
data-val-required کلمه مورد جستجو الزامی است. id Keyword name Keyword type text value
i tried to make an array of words by preg_split but i need some helps on…

peiman F.
- 1,648
- 1
- 19
- 42
0
votes
3 answers
Break a sentence in two parts on first occurrence of a a number
I am in a situation that iIneed to break the line 'Havenlaan 86C Bus 12' into two parts
$str = 'Havenlaan 86C Bus 12';
$regex = '/[ ^\d]/';
$flags = PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY;
$exploded = preg_split( $regex,$str, 2,…

Ranjit Singh
- 45
- 1
- 1
- 5
0
votes
1 answer
Php split array and save result to file
I have 5000 rows in text file separated by new line like:
text1
text2
text3
..etc
I need take them one by one from this file as variables in my script, and then result add to file without overwrite last row.
If i trying to paste all array to form…

Valdemar Z
- 91
- 1
- 1
- 7
0
votes
1 answer
preg_split expression to split the string by a delimiter
I am trying to split the line have space and text enclosed.. I am not getting proper output
$line = '"name" "Brand" "EAN" "shipping" "Combinable"';
$lineArray = preg_split('/^\"\s+\"/', $line);
print_r($lineArray);

B L Praveen
- 1,812
- 4
- 35
- 60
0
votes
1 answer
preg_split on fputcsv to store a array of elements into different columns of csv
I'm trying to store the values of the table in to a csv file for which I used fputcsv function. However it puts the elements into a single column. I need to store the values in three columns.
Code:
foreach ($total as $key => $value)
{
…

Krishna
- 97
- 9
0
votes
1 answer
Preg split table all tds
I want to get all occurrences of tds in a string. At the moment im using $tds = preg_split( '#(?=)#', $toDisplayNotes );
but this does not get all the tds. is it possible to produce an array that looks like this:
array {
[0] =>…

rob
- 13
- 2
0
votes
2 answers
JSON split using preg_split in PHP
I have different servers
$strarrServerIp = array('192.168.123.1','192.168.123.2');
$strarrLogsData = array();
foreach($strarrServerIp as $strServerIp ){
$strCommand = 'ssh abose@' . $strServerIp . ' cat…

Abhishek
- 270
- 1
- 5
- 16
0
votes
1 answer
preg_split url slug and id
I currently have this URL pattern:
foo-bar-1
bar-foo-bar-2
etc
I'd like to get the words separated from the number but I'm having some trouble completely understanding how to do that.
I started with this which got me close:
$slug =…

travisneids
- 593
- 6
- 7
0
votes
1 answer
How to split text by html tags using preg_split?
I have problem with splitting text by html tags.
I'm using CKEditor to editing text and saving results to database.
For better understanding my problem i'm putting sample text from DB
string(3351) "
Etiam at auctor massa. In eget turpis a…

imvanzen
- 83
- 2
- 13
0
votes
0 answers
PHP regex expression for preg_split with multiple periods
I have some text which I need to split into 2 elements based on delimiters "-:." (dash, colon or period)
The below works for me :
$exploded_val = preg_split( "/[-:\.]/", $orig_val );
Problem is that some of the text have multiple periods, in which…

SIndhu
- 677
- 3
- 15
- 21
0
votes
2 answers
Php preg_split for forwardslash?
I've some text that i wish to parse
$str = "text1
text2
text3 I've tried using print_r( preg_split("
", $str)); but it is not giving me the desired output
text2
text3 I've tried using print_r( preg_split("
", $str)); but it is not giving me the desired output

ericlee
- 2,703
- 11
- 43
- 68