preg_split() is a PHP function which allows splitting a string using a regular expression.
Questions tagged [preg-split]
550 questions
2
votes
3 answers
Divide string into associtive array
I have a string:
$string = 'A0695/16 NOTAMN Q) EHAA/QARLT/I /NBO/E /000/999/5155N00430E073 A) EHAA B) 1605260001 C) 1608260900 EST E) REF AIP NETHERLANDS ENR 3.2 UT601 ADD TO ROUTE REMARKS: NOT AVBL FOR TRAFFIC DEP/ARR ETNG, EDDK AND ETNN DURING THE…

flightlevel100
- 21
- 1
2
votes
0 answers
PHP, preg_split pattern (Arabic text )
I am trying to split a text that I got from a .docx (Arabic) using preg-split.
The text sample:
صادر في16 الفقرة الأولى :المتعلق (ج. ر. بتاريخ 8 ذو القعدة 1435 -ويجوز بالتالي إصدار الأمرالفقرة4: القعدة
I need to split my text according to the…

E.Sophia
- 49
- 1
- 12
2
votes
1 answer
Parse rows of data from string and insert into database
I am new to PHP apologize if this is an unworldly question. I am receiving a packet of data with dynamic length on the tcp/ip socket. The packet looks like…

Crazy Engineer
- 325
- 5
- 17
2
votes
1 answer
PHP Regex using preg_split
I need to extract from a string 2 parts and place them inside an array.
$test = "add_image_1";
I need to make sure that this string starts with "add_image" and ends with "_1" but only store the number part at the very end. I would like to use…

Mayron
- 2,146
- 4
- 25
- 51
2
votes
4 answers
Get first 2 sentences in php
We have this code that grabs the first two sentences of a paragraph and it works perfect except for the fact that it only counts periods. It needs to get the first two sentences even if they have exclamation points or question marks. This is what we…

dems59
- 25
- 6
2
votes
4 answers
Split strings by different delimiting character sequences
I have the following strings, that comes with the format country: Cum name, Extra info.
Asia: Asian Cup - Play Offs
Asia: Asian Cup
Asia: World Cup - Qualification - First Stage
Australia: A-League
Belgium: Jupiler League - Championship…

KodeFor.Me
- 13,069
- 27
- 98
- 166
2
votes
4 answers
use preg_split but keep delimiter
I read other related posts, but impossible to make it works in my case.
I have the following text :
This. Is a test. I show. You.
I want to use preg_split using delimiter '. ' (dot + space), but i need to keep delimiter in returned array. Here is…

user2733521
- 439
- 5
- 22
2
votes
1 answer
Making a [code][/code] for BBcode with php regex
I would like to make a [code][/code] tag for bbcode so that what would be inside wouldn't be taken into account by the php regex that I made.
Example :
Hello [b]newbie[/b], to write in bold, use the following : [code][b](YOURTEXT)[/b][/code]
Should…

Northwinter
- 31
- 6
2
votes
1 answer
Need a complex regular expression to split on camel case and numbers
I need to split on capital letters and numbers, with a series of capital letters getting split as an entire word anywhere in the string. It's probably easiest to just explain with examples, see the test script below:
$tests = array('FooBar',…

Michael
- 402
- 3
- 8
2
votes
2 answers
PHP Preg_split split for character ' except preceded by?
I have a problem to split a text by ' character except when ' is preceded by ?.
I used this expression to split my text:
preg_split("/([^?]')/",$this->msg)
This expression works fine, but removes the last character from the splitted strings.
For…

Vincenzo Di Roberto
- 55
- 4
2
votes
1 answer
preg_match() to split a string by another string which is not in apostrophes
I have many strings like this:
parameter_1 >= '23' AND parameter_2 like 'cucurigu AND \picaso' AND parameter_3 IS NULL
And I want to make a preg_split() after every AND which is not inside apostrophes. The output of $matches should be an array with…

besciualex
- 1,872
- 1
- 15
- 20
2
votes
1 answer
Split on / only if surrounded by text
I need to split 1/2 chicken/ greens/egg/tomato/blue cheese/bacon for / only if the / is surrounded by [a-z ] and not by numbers
I have tried:
#[^0-9]\/[^0-9]#i
#[a-z ]\/[a-z ]#i
#(?:[a-z ])\/(?:[a-z ])#i
But it capture also the text
(If it…

Fabrizio
- 3,734
- 2
- 29
- 32
2
votes
2 answers
how to stop duplicate values from being written to text file using php
i have a script that keeps reloading every 2 seconds, i made a code to create a txt file for each user IP and write the user name $name inside it. my problem is that everytime my script reloads it will write the $name of the specific IP again with…

GuestofHonor
- 125
- 4
- 16
2
votes
3 answers
PHP preg_split, split by same characters
I'm trying to split a string with preg_split. Here's an example of the string:
111235622411
I want the output to be like this:
$arr[0] = "111";
$arr[1] = "2";
$arr[2] = "3";
$arr[3] = "5";
$arr[4] = "6";
$arr[5] = "22";
$arr[6] = "4";
$arr[7] =…

pake10
- 21
- 1
2
votes
3 answers
preg_split String into Array at First Non-Numeric Character
I have a string with some numbers and text and I'm trying to split the string at the first non-numeric character.
For Example, I have a few strings like
$value = '150px';
$value = '50em';
$value = '25%';
I've been trying to split the string using…

EHerman
- 1,852
- 7
- 32
- 52