explode

PHP: Split cookie value and count parts

房东的猫 提交于 2019-12-08 07:54:27
问题 I am a PHP beginner and hope someone here can help me with this. I have a string that looks like the following example where the separator is an underscore and the length of the string can vary. The three digit numbers are IDs and the numbers in brackets are counts. Example: 101(2)_102(3)_103(5) I am looking for a way to split this in a way that I can access each ID and each count in order to use them for further calculations etc. I tried using explode but couldn't get this to work. My

Multi Dem php string to array - comma separated, colon separated array

你说的曾经没有我的故事 提交于 2019-12-08 06:22:11
问题 I have a string $string = 'S:1,M:1,L:1,XL:1,XXL:1,3XL:1'; I want to create an array where $array['S'] = 1; $array['M'] = 1; I thought i could explode(',', $string); and then explode(':', $string); again ;-) but that doesn't work at all. 回答1: Yes, you can explode() twice, but the second one has to be in a loop: $string = 'S:1,M:1,L:1,XL:1,XXL:1,3XL:1'; // Split on the commas $sizes = explode(",", $string); // Output array $quantities = array(); // Loop over the first explode() result foreach (

PHP explode over every other word with a twist?

独自空忆成欢 提交于 2019-12-08 03:45:27
Duplicate: Explode over every other word $string = "This is my test case for an example." If I do explode based on ' ' I get an Array('This','is','my','test','case','for','an','example.'); What I want is an explode for every other space. I'm looking for the following output: Array( [0] => Array ( [0] => This is [1] => is my [2] => my test [3] => test case [4] => case for [5] => for example. ) so basically every 2 worded phrases is outputted. Anyone know a solution???? Sylvain this will provide the output you're looking for $string = "This is my test case for an example."; $tmp = explode(' ',

PHP explode over every other word with a twist?

心不动则不痛 提交于 2019-12-08 03:29:58
问题 Duplicate: Explode over every other word $string = "This is my test case for an example." If I do explode based on ' ' I get an Array('This','is','my','test','case','for','an','example.'); What I want is an explode for every other space. I'm looking for the following output: Array( [0] => Array ( [0] => This is [1] => is my [2] => my test [3] => test case [4] => case for [5] => for example. ) so basically every 2 worded phrases is outputted. Anyone know a solution???? 回答1: this will provide

Parallel to PHP's “explode” in C: Split char* into char* using delimiter [duplicate]

左心房为你撑大大i 提交于 2019-12-08 01:27:25
This question already has answers here : Closed 7 years ago . Possible Duplicate: Split string with delimiters in C I'm searching a good way to "explode" a char* into other char* using a delimiter. My delimiter will be # You can use strtok like CrazyCasta said but his/hers code is wrong. char *tok; char *src = malloc(strlen(srcStr) + 1); memcpy(src, srcStr); tok = strtok(src, "#"); if(tok == NULL) { printf("no tokens found"); free(src); return ???; } printf("%s ; ", tok); while((tok = strtok(NULL, "#"))) printf("%s ; ", tok); printf("\n"); free(str); Be aware that strtok has to be called the

How do you EXPLODE CSV line with a comma in value?

谁都会走 提交于 2019-12-07 09:18:16
问题 "AMZN","Amazon.com, Inc.",211.22,"11/9/2011","4:00pm","-6.77 - -3.11%",4673052 Amazon.com, Inc. is being treated as 2 values instead of one. I tried this $data = explode( ',', $s); How do I modify this to avoid the comma in the value issue? 回答1: You should probably look into str_getcsv() (or fgetcsv() if you're loading the CSV from a file) This will read the CSV contents into an array without the need for exploding etc. Edit- to expand upon the point made by Pekka, if you're using PHP < 5.3

python 饼状图

徘徊边缘 提交于 2019-12-06 20:31:33
1 #coding=utf8 2 import matplotlib as mpl 3 import matplotlib.pyplot as plt 4 mpl.rcParams['font.sans-serif'] = ['SimHei'] 5 mpl.rcParams['font.serif'] = ['SimHei'] 6 mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题,或者转换负号为字符串 7 8 9 # 生成数据 10 labels = ['A', 'B', 'C', 'D', u'其他'] 11 share = [0.45, 0.25, 0.15, 0.05, 0.10] 12 13 # 设置分裂属性 14 explode = [0, 0.1, 0, 0, 0] 15 16 # 分裂饼图 17 plt.pie(share, explode = explode, 18 labels = labels, autopct = '%3.1f%%', 19 startangle = 180, shadow = True, 20 colors = ['c', 'r', 'gray', 'g', 'y']) 21 22 # 标题 23 plt.title(u'2017年笔记本电脑市场份额') 24

Calling PHP explode and access first element? [duplicate]

拟墨画扇 提交于 2019-12-06 16:43:06
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: PHP syntax for dereferencing function result I have a string, which looks like 1234#5678 . Now I am calling this: $last = explode("#", "1234#5678")[1] Its not working, there is some syntax error...but where? What I expect is 5678 in $last . Is this not working in PHP? 回答1: Array dereferencing is not possible in the current PHP versions (unfortunately). But you can use list [docs] to directly assign the array

Explode String in PHP

烂漫一生 提交于 2019-12-06 07:35:51
If I have a string "123x456x78", how could I explode it to return an array containing "123" as the first element and "456" as the second element? Basically, I want to take strings that are followed by "x" (which is why "78" should be thrown out). I've been messing around with regular expressions, but am having trouble. Thanks! EDIT : if the string were "123x456x78x" I would need three elements: "123", "456", "78". Basically, for each region following an "x", I need to record the string up until the next "x". Loads of different ways, but here's a RegEx as you were trying that: $str =

How does one break a string down by capital letters with PHP?

自闭症网瘾萝莉.ら 提交于 2019-12-06 05:11:05
问题 I have a string: CamelCaseString I want to explode(), split(), or some better method on capital letters to break this string down into the individual words. What's the simplest way to do this? --- SOLUTION UPDATE --- This link is to a slightly different question, but I think the answer will generally be more useful than the answers to the current question on this page: How can I add a space in string at capital letters, but keep continuous capitals together using PHP and a Regex? 回答1: You