preg-split

PHP preg_split with two delimiters and capture only one

浪子不回头ぞ 提交于 2019-12-12 05:54:42
问题 Really poor at regular expressions, sorry in advance! I've tried my best to work out how to split a string into a array with two delimiters and still capture one and include it in the final array. preg_split seems ideal for this but my regular expression is letting me down. If for example, I've the string foo = bar AND bar=foo ; I want to split the string at either a space, or the = character BUT keep the = so the array would look like: Array ( [0] => foo [1] => = [2] => bar [3] => AND [4] =>

Convert JSON string to array WITHOUT json_decode

孤街醉人 提交于 2019-12-12 01:49:46
问题 I am using PHP on shared server to access external site via API that is returning JSON containing 2 levels of data (Level 1: Performer & Level 2: Category array inside performer). I want to convert this to multidimensional associative array WITHOUT USING json_decode function (it uses too much memory for this usage!!!) Example of JSON data: [ { "performerId": 99999, "name": " Any performer name", "category": { "categoryId": 99, "name": "Some category name", "eventType": "Category Event" },

preg_split string to multidimensional array

点点圈 提交于 2019-12-11 12:57:26
问题 Hello just looking for some help as I've gotten stuck I have two Strings: C:\Users\Bob\My Documents /Users/Bob/Documents That gets put through preg_split('/(?<=[\/\\\])(?![\/\\\])/', $string) that returns Array ( [0] => C:\ [1] => Users\ [2] => Bob\ [3] => My Documents ) Array ( [0] => / [1] => Users/ [2] => Bob/ [3] => Documents ) I need Array ( [C:\] => Array ( [Users] => Array ( [Bob] => Array ( [My Documents] => array() ) ) ) ) Array ( [/] => Array ( [Users] => Array ( [Bob] => Array (

php preg_split doesn't recognise spaces

孤者浪人 提交于 2019-12-11 05:28:31
问题 I copy & paste football games from Betfair e.g. "Bournemouth v Tottenham" and this is stored in a MySQL database. However, when I try: preg_split('/\s+/', $row['match']); As suggested on here previously it doesn't split on the first space (my ultimate goal would be something like'/\s[v]\s/'). When I manually overwrite the field in the database as " v " it then splits it correctly. What could it be treating this character as that appears as a space both in the browser and in PHPMyAdmin but

PHP preg_split if not inside curly brackets

江枫思渺然 提交于 2019-12-11 01:26:10
问题 I'm makin' a scripting language interpreter using PHP. I have this code in that scripting language: write {Hello, World!} in either the color {blue} or {red} or {#00AA00} and in either the font {Arial Black} or {Monaco} where both the color and the font are determined randomly (Yes, it's hard to believe but that's the syntax) Which regex must I use to split this (split by spaces) but only if not inside the curly brackets. So I want to turn the above code into this array: write Hello, World!

Using Preg_Split With Multiple Spaces

点点圈 提交于 2019-12-10 21:03:57
问题 I'm having a bit of trouble figuring this out. I have lines of data such as this: $data = "Alpha Natural Resources Inc COM 02076X102 2,077 45,700 x I am looking to "explode" this line wherever there is more than one space. The problem that I have run into is that I have only found solutions that blow up the line where there is one space or more - I am looking to blow up this line where there is more than one space, but not just one space (so that Alpha Natural Resources Inc stay together, for

PHP: How to split a UTF-8 string?

扶醉桌前 提交于 2019-12-10 14:14:32
问题 I have the following code which is not working with UTF-8 characters. How can I fix it? $seed = preg_split('//u', $seed, -1, PREG_SPLIT_NO_EMPTY); $seed = str_split('АБВГДЕЖЗ'); // and any other characters shuffle($seed); // probably optional since array_is randomized; this may be redundant $code = ''; foreach (array_rand($seed, 5) as $k) $md5_hash .= $seed[$k]; //We don't need a 32 character long string so we trim it down to 5 $security_code = $code; I have tried this code: $seed = preg

PHP preg_split: Split string by other strings

被刻印的时光 ゝ 提交于 2019-12-09 18:35:51
问题 I want to split a large string by a series of words. E.g. $splitby = array('these','are','the','words','to','split','by'); $text = 'This is the string which needs to be split by the above words.'; Then the results would be: $text[0]='This is'; $text[1]='string which needs'; $text[2]='be'; $text[3]='above'; $text[4]='.'; How can I do this? Is preg_split the best way, or is there a more efficient method? I'd like it to be as fast as possible, as I'll be splitting hundreds of MB of files. 回答1: I

Regular expression for preg_split() by new line

喜欢而已 提交于 2019-12-09 16:17:57
问题 This is my file: 0.0 5.0 5.0 6.0 7.0 2.0 5.0 2.0 1.0 5.0 5.0 1.0 2.0 7.1 5.0 5.0 0.0 5.0 5.0 5.0 2.0 5.0 1.0 5.0 6.0 6.0 6.0 6.0 1.0 7.1 5.0 5.0 0.0 6.0 1.0 6.0 5.0 5.0 1.0 6.0 5.0 7.0 1.0 5.0 6.0 6.0 5.0 6.0 0.0 5.0 2.0 1.0 6.0 5.0 6.0 2.0 1.0 2.0 1.0 5.0 7.0 5.0 1.0 5.0 0.0 7.0 1.0 1.0 2.0 1.0 5.0 6.0 2.0 2.0 5.0 2.0 2.0 6.0 2.0 7.0 0.0 5.0 5.0 6.0 5.0 2.0 5.0 1.0 2.0 5.0 5.0 5.0 5.0 1.0 1.0 5.0 0.0 2.0 6.0 1.0 5.0 7.0 5.0 1.0 6.0 7.0 1.0 5.0 1.0 2.0 2.0 1.0 5.0 6.0 5.0 2.0 6.0 7.0 0.0 5.0

use preg_split to split chords and words

回眸只為那壹抹淺笑 提交于 2019-12-08 22:10:12
问题 I'm working on a little piece of code playing handling song tabs, but i'm stuck on a problem. I need to parse each song tab line and to split it to get chunks of chords on the one hand, and words in the other. Each chunk would be like : $line_chunk = array( 0 => //part of line containing one or several chords 1 => //part of line containing words ); They should stay "grouped". I mean by this that it should split only when the function reaches the "limit" between chords and words. I guess I