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
empty return preg_split [how]?
i have string like this
$string = '$foo$wow$123$$$ok$';
i want to return empty string and save string in array like this
0 = foo
1 = wow
2 = 123
3 =
4 =
5 = ok
i use PREG_SPLIT_NO_EMPTY, i know when make PREG_SPLIT_NO_EMPTY return is not empty,…

pwcahyo
- 67
- 1
- 10
0
votes
1 answer
Trying to dynamically write a table with PHP based on SQL Query
I started learning learning PHP a couple of days ago and have started to make an SQL Database management webpage using AJAX. I am having a problem with errors if I restrict the search to less than all [*] the column's.
Because of this I thought it…

synthet1c
- 6,152
- 2
- 24
- 39
0
votes
2 answers
php preg split a string
I have a numeric string and I'd need to split it in groups of 2 starting from right, but not more than three groups.
To understand, the 3 groups are 'copper', 'silver' and 'gold' and the starting value is a synthetic money amount. For example:
10…

the_nutria
- 75
- 5
0
votes
2 answers
How to stop splitting within a pair of second delimiter in preg_split (PHP)?
I need to generate an array with preg_split, as implode('', $array) can re-generate the original string. `preg_split of
$str = 'this is a test "some quotations is her" and more';
$array = preg_split('/( |".*?")/', $str, -1,…

Googlebot
- 15,159
- 44
- 133
- 229
0
votes
2 answers
Explode string by semicolon using php's preg_split
I have this string (it's an apple .strings file):
/* this is a comment line; it may contain semicolons */
"you have here some text; also may contain semicolons" = "some other text;";
/* this is a comment line; it may contain semicolons */
"you have…

Marvin Saldinger
- 1,290
- 1
- 16
- 34
0
votes
2 answers
preg_split does not work with price extraction
I have these types of possible content in the strings I'm breaking up:
$string = "$100 USD per year"
$string = "$100USD per year"
$string = "100 USD per year"
$string = "100EUR per year"
$string = "€100EUR per year"
$string = "€100 EUR per…

ipruthi
- 144
- 2
- 8
0
votes
2 answers
preg_split url with a regular expression
I have an string e.g.:
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…

netS
- 50
- 1
- 7
0
votes
3 answers
Replace only the second html tag
I want to replace the second h2 tag to h3 and I hope someone can help me with a replacement regex, or maybe a preg_split - I am not exactly sure.
For example, this:
My text one
My text two
text …My text three
Should…
bklups
- 117
- 9
0
votes
2 answers
php preg_split seems to crash on large strings
I have been trying to load the USDA nutritional data into a mysql database from the ascii version of the data. I used the scripts from here and everything came in except the NUT_DATA.txt file which is ~34MB in size. The file loads correctly using…

zzzz
- 682
- 10
- 16
0
votes
3 answers
preg_split with regex giving incorrect output
I'm using preg_split to an string, but I'm not getting desired output. For example
$string = 'Tachycardia limit_from:1900-01-01 limit_to:2027-08-29 numresults:10 sort:publication-date direction:descending facet-on-toc-section-id:Case Reports';
$vals…

Sharique
- 4,199
- 6
- 36
- 54
0
votes
3 answers
Print_r is not working with preg_split
I writing a function to search within my database. I wanted to eliminate uneccessary white spaces between words so I used preg_split. I have not used preg split before so I used print_r to see if it did what I was hoping for it to do (elimminate…

Octavius
- 583
- 5
- 19
0
votes
2 answers
preg_split() Regex for Initials Lastname
I have a name pattern looking like this:
F. O. O. Bar
F. Oobar
F. O. Obar
I'm currently trying to develop a regex that lets me split names in firstname, maybe initials and surname according to one of these.
foreach($authors as $author) {
$arr =…

sonOfRa
- 1,280
- 11
- 21
0
votes
1 answer
string to array, split by single and double quotes, ignoring escaped quotes
i have another php preg_split question which is very similar to my last question, although i fear the solution will be quite a bit more complicated. as before, i'm trying to use php to split a string into array components using either " or ' as the…

mulllhausen
- 4,225
- 7
- 49
- 71
0
votes
1 answer
php regex changing split to preg_split - specific example
Lots of questions similar but I have a specific example I would like some help with please.
Migrating older php 5.2 code to 5.3
for($s=0;$s

ShopifyBuilder
- 7
- 3
0
votes
1 answer
preg_split at the line before an item
I'm creating a automatic email response, but I don't want to show the original email in the response. There is a line in the email that they must respond above. But email programs add a line like "On Aug 21, 2012, at 11:30 PM, David wrote:" before…

David Fairbanks
- 638
- 7
- 17