explode

PHP: Split string into array, like explode with no delimiter

混江龙づ霸主 提交于 2019-12-17 08:51:45
问题 I have a string such as: "0123456789" and need to split EACH character into an array. I for the hell of it tried: explode('', '123545789'); But it gave me the obvious: Warning: No delimiter defined in explode) .. How would I come across this? I can't see any method off hand, especially just a function 回答1: $array = str_split("0123456789bcdfghjkmnpqrstvwxyz"); str_split takes an optional 2nd param, the chunk length (default 1), so you can do things like: $array = str_split("aabbccdd", 2); //

Unexpected bracket '[' - PHP [duplicate]

拈花ヽ惹草 提交于 2019-12-17 04:35:43
问题 This question already has answers here : PHP Array Syntax Parse Error Left Square Bracket “[” [closed] (2 answers) Closed 5 years ago . I'm writing a small repository for my little app team's Java code, and I have this error all over my code. $base = explode(".", $class)[0]; The problem occurs only with this one line of code, every time. As far as I know, the above is correct PHP syntax, so what's going on? Parse error : syntax error, unexpected '[' in .../mitc/code/index.php on line 27 If

Explode string by one or more spaces or tabs

社会主义新天地 提交于 2019-12-17 04:22:18
问题 How can I explode a string by one or more spaces or tabs? Example: A B C D I want to make this an array. 回答1: $parts = preg_split('/\s+/', $str); 回答2: To separate by tabs: $comp = preg_split("/[\t]/", $var); To separate by spaces/tabs/newlines: $comp = preg_split('/\s+/', $var); To seperate by spaces alone: $comp = preg_split('/ +/', $var); 回答3: This works: $string = 'A B C D'; $arr = preg_split('/[\s]+/', $string); 回答4: The author asked for explode, to you can use explode like this

Php multiple delimiters in explode

≯℡__Kan透↙ 提交于 2019-12-17 03:51:56
问题 I have a problem, I have a string array, and I want to explode in different delimiter. For Example $example = 'Appel @ Ratte'; $example2 = 'apple vs ratte' and I need an array which is explode in @ or vs. I already wrote a solution, but If everybody have a better solution please post here. private function multiExplode($delimiters,$string) { $ary = explode($delimiters[0],$string); array_shift($delimiters); if($delimiters != NULL) { if(count($ary) <2) $ary = $this->multiExplode($delimiters,

Php multiple delimiters in explode

帅比萌擦擦* 提交于 2019-12-17 03:50:51
问题 I have a problem, I have a string array, and I want to explode in different delimiter. For Example $example = 'Appel @ Ratte'; $example2 = 'apple vs ratte' and I need an array which is explode in @ or vs. I already wrote a solution, but If everybody have a better solution please post here. private function multiExplode($delimiters,$string) { $ary = explode($delimiters[0],$string); array_shift($delimiters); if($delimiters != NULL) { if(count($ary) <2) $ary = $this->multiExplode($delimiters,

php Explode on an Exact Word

Deadly 提交于 2019-12-14 04:00:42
问题 Is it possible to have php explode work on an exact word? For example, I wish to split the string: London Luton to Paris However, php explode will find the first occurrence of 'to' which is in 'Luton'. This string is also possible: Paris to London Luton Which will correctly explode as the 'to' appears first. Ideally, I wish for the explode to be case insensitive which I believe explode currently is. I figure however that RegEx is probably a better way to go here. 回答1: simple solution with

Php - explode a string with two delimiters

送分小仙女□ 提交于 2019-12-14 02:50:15
问题 $string = 'folder1:image1.jpg|folder2:image2.jpg|folder3:image3.jpg'; I need to explode the string to get the following result: <img src="/folder1/image1.jpg" /> <img src="/folder2/image2.jpg" /> <img src="/folder3/image3.jpg" /> It's not a problem with one delimiter but I have two delimiters and don't know how to do it: $imagedata = explode("|", $string); foreach($imagedata as $image) { echo "$image<br />"; } 回答1: use this: $string = 'folder1:image1.jpg|folder2:image2.jpg|folder3:image3.jpg'

explode an array of delimited strings into two arrays

强颜欢笑 提交于 2019-12-14 02:21:45
问题 I have the following array: Array ( [0] => 10-7 [1] => 11-3 [2] => 11-7 [3] => 12-3 [4] => 12-7 [5] => 13-3 [6] => 13-7 [7] => 14-3 [8] => 14-7 [9] => 15-7 ) that I need to split into two arrays using "-" as delimiter: Array ( [0] => 10 [1] => 11 [2] => 11 [3] => 12 [4] => 12 [5] => 13 [6] => 13 [7] => 14 [8] => 14 [9] => 15 ) and Array ( [0] => 7 [1] => 3 [2] => 7 [3] => 3 [4] => 7 [5] => 3 [6] => 7 [7] => 3 [8] => 7 [9] => 7 ) Is there anything like array_explode that does what I want? or a

PHP Explode and Get_Url: Not Showing up the URL

末鹿安然 提交于 2019-12-13 20:28:07
问题 its a little bit hard to understand. in the header.php i have this code: <? $ID = $link; $url = downloadLink($ID); ?> I get the ID with this Variable $link --> 12345678 and with $url i get the full link from the functions.php in the functions.php i have this snippet function downloadlink ($d_id) { $res = @get_url ('' . 'http://www.example.com/' . $d_id . '/go.html'); $re = explode ('<iframe', $res); $re = explode ('src="', $re[1]); $re = explode ('"', $re[1]); $url = $re[0]; return $url; }

str_getcsv not parsing the data correctly

ぃ、小莉子 提交于 2019-12-13 16:23:23
问题 I have a problem with str_getcsv function for PHP. I have this code: <?php $string = '#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=714000,RESOLUTION=640x480,CODECS="avc1.77.30, mp4a.40.34"'; $array = str_getcsv($string, ",", '"'); print_r($array); Which should return: Array ( [0] => #EXT-X-STREAM-INF:PROGRAM-ID=1 [1] => BANDWIDTH=714000 [2] => RESOLUTION=640x480 [3] => CODECS=avc1.77.30, mp4a.40.34 ) But instead, it is returning: Array ( [0] => #EXT-X-STREAM-INF:PROGRAM-ID=1 [1] => BANDWIDTH