explode

Handling new lines in php

删除回忆录丶 提交于 2019-12-20 02:15:48
问题 I have form in html where user can put the text in text area. I save the content of text area into MySQL database (in field of type TEXT). Then I somewhere in my aplication I need load that text and put it into array where in each index will be one line of the text. <textarea rows="10" cols="80"> Row one Row two Row tree </textarea> array (output in "php pseudocode"): $array = array(); $array[0] = Row one; $array[1] = Row two; $array[2] = Row tree; How I do it: I save it to db then I load it

SQL: Explode an array

淺唱寂寞╮ 提交于 2019-12-19 09:16:56
问题 I have a table that contains JSON objects. Each JSON object contains an array in square brackets, separated by commas. How can I access any element in the square bracket array, for example "Matt", using SQL? {"str": [ 1, 134, 61, "Matt", {"action.type":"registered","application":491,"value":423,"value2":12344}, ["application"], [], "49:0" ] } I am using 'Hive' ontop of Hadoop. If you know how to do this in SQL, that is fine :) 回答1: You can do this in Hive as follows: First you need a JSON

Javascript - explode equivilent?

ぐ巨炮叔叔 提交于 2019-12-19 02:27:14
问题 So, I have a string with the delimiter | , one of the sections contains "123", is there a way to find this section and print the contents? something like PHP explode (but Javascript) and then a loop to find '123' maybe? :/ 回答1: var string = "123|34|23|2342|234", arr = string.split('|'), i; for(i in arr){ if(arr[i] == 123) alert(arr[i]); } Or: for(i in arr){ if(arr[i].indexOf('123') > -1) alert(arr[i]); } For more information on string based manipulation and functions see: https://developer

Serialize or Implode

淺唱寂寞╮ 提交于 2019-12-18 13:17:20
问题 I need to store lots of two-dimensional arrays inside database and was not sure what to use: serialize or implode . So I did a few tests, to find out which one is working faster and came to the conclusion it was serialize : Execution times: 1'000'000 Serialize: 1.4974119663239 seconds Implode: 2.5333571434021 seconds Explode: 4.0185871124268 seconds Unserialize: 1.6835169792175 seconds So the question: Why is implode+explode so much slower then serialize+unserialize ? PS: I found this

php url explode

社会主义新天地 提交于 2019-12-18 08:26:15
问题 I am wanting to grab my product from my url. For example: http://www.website.com/product-category/iphone I am wanting to grab the iphone and that is fine with my code but I have a dropdown to sort products and which clicked will change the url and add a query like: http://www.website.com/product-category/iphone?orderby=popularity http://www.website.com/product-category/iphone?orderby=new http://www.website.com/product-category/iphone?orderby=price http://www.website.com/product-category

python 数据可视化 饼状图绘制

可紊 提交于 2019-12-17 21:39:31
""" author:魏振东 data:2019.12.13 func:饼图绘制 """ import matplotlib . pyplot as plt import xlrd x1 = xlrd . open_workbook ( "软件开发新技术I学生名单.xls" ) # 获取sheet sheet1 = x1 . sheet_by_index ( 0 ) dict1 = { } for i in range ( 1 , int ( sheet1 . nrows ) ) : if sheet1 . cell_value ( i , 5 ) == '男' : dict1 . setdefault ( '男' , [ ] ) . append ( sheet1 . cell_value ( i , 5 ) ) else : dict1 . setdefault ( '女' , [ ] ) . append ( sheet1 . cell_value ( i , 5 ) ) man = round ( len ( dict1 [ '男' ] ) / ( len ( dict1 [ '男' ] ) + len ( dict1 [ '女' ] ) ) , 2 ) woman = round ( len ( dict1 [ '女' ] ) / ( len ( dict1 [ '男'

Mysql where id is in array [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-17 20:05:38
问题 This question already has answers here : Passing an array to a query using a WHERE clause (18 answers) Closed 5 years ago . I have a string of ids like 1,2,3,4,5 and I want to be able to list all rows in mysql where the ID is contained in that list. I assumed the easiest way would be to turn the string into an array and then match in ($array) but it doesn't work for me - no errors etc but it returns no rows: $string="1,2,3,4,5"; $array=array_map('intval', explode(',', $string)); $query=mysqli

explode textarea php (at new lines)

冷暖自知 提交于 2019-12-17 17:42:23
问题 can I do: explode("\n", $_POST['thetextarea']); and have it work on all platforms? (The question I am asking is will it ever be \r\n and not just \n") EDIT: I forgot to mention that I am saving $_POST['thetextarea'] to a mysql database VARCHAR 255. It seems \r\n is converted to \n. 回答1: This will do the trick given \r\n , \r or \n : preg_split('/\r\n|[\r\n]/', $_POST['thetextarea']) 回答2: You should use: explode("\r\n", $_POST['thetextarea']); It will always be the same. Browsers and other

How can I explode and trim whitespace?

假如想象 提交于 2019-12-17 17:24:21
问题 For example, I would like to create an array from the elements in this string: $str = 'red, green, blue ,orange'; I know you can explode and loop through them and trim: $arr = explode(',', $str); foreach ($arr as $value) { $new_arr[] = trim($value); } But I feel like there's a one line approach that can handle this. Any ideas? 回答1: You can do the following using array_map: $new_arr = array_map('trim', explode(',', $str)); 回答2: An Improved answer preg_split ('/(\s*,*\s*)*,+(\s*,*\s*)*/', 'red,

How do I explode an integer

巧了我就是萌 提交于 2019-12-17 16:43:40
问题 the answer to this could be easy. But I'm very fresh to programming. So be gentle... I'm at work trying to do a quick fix for one of your customers. I want to get the total numbers of digits in a integer, and then explode the integer: rx_freq = 1331000000 ( = 10 ) $array[0] = 1 $array[1] = 3 . . $array[9] = 0 rx_freq = 990909099 ( = 9 ) $array[0] = 9 $array[1] = 9 . . $array[8] = 9 I'm not able to use explode, as this function need a delimiter. I've searched the eyh'old Google and