Questions tagged [preg-split]

preg_split() is a PHP function which allows splitting a string using a regular expression.

550 questions
0
votes
2 answers

Split PHP Variable in to array

A php variable contains $string = "256 Engineering Maths-I 21 -1 21 F"; printing $string gives output 256 Engineering Maths-I 21 -1 21 F this variable should split in to $n[0] = "256"; $n[1] = "Engineering Maths-I"; $n[2] = "21"; $n[3] =…
ManojGeek
  • 1,977
  • 2
  • 16
  • 23
0
votes
1 answer

With PHP, how can I split a string into an array where the delimiters are a variable string enclosed with braces like '[Ab]'

Using PHP, How can I split the following string "Random words [Ab]another few words here [Bx]and yet a [Sq4]few more" into the following array: array[0] = 'Random words ' array[1] = '[Ab]' array[2] = 'another few words here ' array[3] = '[Bx]'…
dnpage
  • 95
  • 1
  • 6
0
votes
1 answer

How can I ignore "XXX" titles in my data parsing script?

I've tried and it doesn't seem to work. Any help would be greatly appreciated. CODE: foreach (glob('mov/Alene*.mov') as $filename){ $theData = file_get_contents($filename) or die("Unable to retrieve file data"); } $string = $theData; $titles…
ValleyDigital
  • 1,460
  • 4
  • 21
  • 37
0
votes
1 answer

Php Extracting text between the characters

I get a response from a source in the string as page site not active I need to extract this data to an array as: Array ( [0] => page [1] => ${CLICK_URL} [2] => _top [3] => >site not active …
Srikanth
  • 13
  • 8
0
votes
2 answers

PHP preg-split text-string telephone-numbers

please help me with the following problem: $my_string = 'here is some text and my number: +43 (0) 123 456 - 78 and some more text and a different number + 43(0) 1234/ 567-789 and a final text'; what i need is something like…
user1824042
0
votes
2 answers

preg_split using PREG_SPLIT_DELIM_CAPTURE with an array of delims

Note: I recently asked this question but it turns out the solution I'm looking for is more advanced than I initially thought. Using preg_split, how would I split this up, note that the string before the delimiters varies: $string = "big red apple…
johnpecan
  • 9
  • 4
0
votes
1 answer

Opposite of a Regex

The rules of the regex are simple: Split by NOT: a whitespace " " followed by 'OR' or '|' : Example: "thing to say" france (true) "thing to say" OR thing (false) "thing to say" | thing (false) I'm trying to find a regex to help me do that…
Alucard
  • 1,814
  • 1
  • 21
  • 33
0
votes
1 answer

Preg_split screws up the BR tag?

I am struggling with this one for half a day now and i can't seem to get it right. I have a custom function in my wordpress site, that automatically creates an excerpt. This all goes well, but for some (i guess logical) reason it also cuts off the…
RobbertT
  • 253
  • 2
  • 5
  • 14
0
votes
3 answers

Parse formatted text with 2 delimiters to generate two arrays

I have a little problem I need to sort. I want to either remove a part of a string or split it. What I want to end up doing is splitting into 2 variables where I have "One, Two, Three" and "1, 2, 3" , I'm not sure if I can split it into two or if I…
snookian
  • 863
  • 6
  • 13
  • 35
0
votes
4 answers

separate string based on shortcodes

I need a preg function which do the following job for following string- string = {my_special_shortcode_name var1='some_var1' var2='some_var2' var3='some_var3'} and the extracted string must look like- Array( 'var1' => 'some_var1', 'var2' =>…
ashutosh
  • 1,192
  • 5
  • 22
  • 46
0
votes
3 answers

PHP preg_split delimiter pattern, split at character chain

With the following string: $str = '["one","two"],a,["three","four"],a,,a,["five","six"]'; preg_split( delimiter pattern, $str ); How would I have to set up the delimiter pattern to obtain this result: $arr[0] = '["one","two"]'; $arr[1] =…
Philipp Werminghausen
  • 1,142
  • 11
  • 29
0
votes
2 answers

preg_split disabled on a free server?

I'm developing a PHP script which use the preg_split function. In my computer, using EasyPhp everything works but when I put the files on-line on a free space the function preg_split seems not to work (I have no error message on the screen but the…
Nicolaesse
  • 2,554
  • 12
  • 46
  • 71
0
votes
1 answer

split a string on semicolons taking into account strings and escaped quotes or semicolons

I'm still trying to figure out a way to take into account escaped quotes like "test\";nosplit" or 'test\';nosplit' So far I have something like this: preg_split('#(^;)|(;$)|(?
qwertymk
  • 34,200
  • 28
  • 121
  • 184
0
votes
5 answers

Converting big String back to Array - PHP

[Check My EDIT for better Explanation] I need some help with a very big string i have. Its like this: $big_string = "TinteiroID:1#TinteiroLABEL:HP CB335EE#TinteiroREF:CB335EE#TinteiroMARCA:HP#TinteiroGENERO:Tinteiro Preto…
Fábio Antunes
  • 16,984
  • 18
  • 75
  • 96
0
votes
1 answer

PHP Regular Expression to split a csv string with optional enveloping quotiation marks

Given is a csv-string that contains an unknown number of blocks of text, splitted by semicolons (;). Sometimes, but not always, the text blocks are enveloped in quotation marks ("). If they are, then semicolons may appear in the text block. I am…
Majiy
  • 1,890
  • 2
  • 24
  • 32