explode

explode error \\r\\n and \\n in windows and linux server

半世苍凉 提交于 2019-11-30 22:50:32
I have used explode function to get textarea's contain into array based on line. When I run this code in my localhost (WAMPserver 2.1) It work perfectly with this code : $arr=explode("\r\n",$getdata); When I upload to my linux server I need to change above code everytime into : $arr=explode("\n",$getdata); What will be the permanent solution to me. Which common code will work for me for both server? Thank you The constant PHP_EOL contains the platform-dependent linefeed, so you can try this: $arr = explode(PHP_EOL, $getdata); But even better is to normalize the text, because you never know

Counting the number of times a character occurs in a string in C

ⅰ亾dé卋堺 提交于 2019-11-30 21:56:39
I'm new to C, and I'm working on my own explode like function. I'm trying to count how many times a specified character occurs in a string. int count_chars(char * string, char * chr) { int count = 0; int i; for (i = 0; i < sizeof(string); i++) { if (string[i] == chr) { count++; } } return count; } It just returns 0 every time. Can anyone explain why, please? :) Your code is hopelessly flawed. Here's how it should look like: int count_chars(const char* string, char ch) { int count = 0; int i; // We are computing the length once at this point // because it is a relatively lengthy operation, //

php count the number of strings after exploded

女生的网名这么多〃 提交于 2019-11-30 18:53:26
Here is my code <?php $string = 'a|b|c|d|e|f'; $tags = explode('|' , $string); foreach($tags as $i =>$key) { $i >0; echo $i.' '.$key .'</br>'; } ?> the output is 0 a 1 b 2 c 3 d 4 e 5 f What i'm try to count the number of strings after i exploded | (it should be 6 for my example) also i need my $i to start from 1 not 0 Any idea please ? Thank you. <?php $string = 'a|b|c|d|e|f'; $tags = explode('|' , $string); foreach($tags as $i =>$key) { echo $i.' '.$key .'</br>'; } ?> Try using: echo count($tags); // Output of 6 Arrays start with a key of 0, not one. So when using anything else apart from

Alternative of php's explode/implode-functions in c#

左心房为你撑大大i 提交于 2019-11-30 10:45:31
are there a similar functions to explode/implode in the .net-framework? or do i have to code it by myself? String.Split() will explode, and String.Join() will implode. The current answers are not fully correct , and here is why: all works fine if you have a variable of type string[] , but in PHP, you can also have KeyValue arrays, let's assume this one: $params = array( 'merchantnumber' => "123456789", 'amount' => "10095", 'currency' => "DKK" ); and now call the implode method as echo implode("", $params); your output is 12345678910095DKK and, let's do the same in C#: var kv = new Dictionary

Serialize or Implode

試著忘記壹切 提交于 2019-11-30 09:34:49
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 question already, but it is not exactly what I am asking. My idea is that explode / implode operate on strings

Split a MYSQL string from GROUP_CONCAT into an ( array, like, expression, list) that IN () can understand

让人想犯罪 __ 提交于 2019-11-30 06:52:23
This question follows on from MYSQL join results set wiped results during IN () in where clause? So, short version of the question. How do you turn the string returned by GROUP_CONCAT into a comma-seperated expression list that IN() will treat as a list of multiple items to loop over? N.B. The MySQL docs appear to refer to the "( comma, seperated, lists )" used by IN () as 'expression lists', and interestingly the pages on IN() seem to be more or less the only pages in the MySQL docs to ever refer to expression lists. So I'm not sure if functions intended for making arrays or temp tables would

Counting the number of times a character occurs in a string in C

断了今生、忘了曾经 提交于 2019-11-30 05:39:10
问题 I'm new to C, and I'm working on my own explode like function. I'm trying to count how many times a specified character occurs in a string. int count_chars(char * string, char * chr) { int count = 0; int i; for (i = 0; i < sizeof(string); i++) { if (string[i] == chr) { count++; } } return count; } It just returns 0 every time. Can anyone explain why, please? :) 回答1: Your code is hopelessly flawed. Here's how it should look like: int count_chars(const char* string, char ch) { int count = 0;

php count the number of strings after exploded

情到浓时终转凉″ 提交于 2019-11-30 03:51:25
问题 Here is my code <?php $string = 'a|b|c|d|e|f'; $tags = explode('|' , $string); foreach($tags as $i =>$key) { $i >0; echo $i.' '.$key .'</br>'; } ?> the output is 0 a 1 b 2 c 3 d 4 e 5 f What i'm try to count the number of strings after i exploded | (it should be 6 for my example) also i need my $i to start from 1 not 0 Any idea please ? Thank you. 回答1: <?php $string = 'a|b|c|d|e|f'; $tags = explode('|' , $string); foreach($tags as $i =>$key) { echo $i.' '.$key .'</br>'; } ?> Try using: echo

How can I explode and trim whitespace?

旧时模样 提交于 2019-11-29 18:54:04
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? You can do the following using array_map : $new_arr = array_map('trim', explode(',', $str)); An Improved answer preg_split ('/(\s*,*\s*)*,+(\s*,*\s*)*/', 'red, green thing ,, ,, blue ,orange'); Result: Array ( [0] => red [1] => green thing [2] => blue [3] => orange )

PHP table from explode array

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 18:01:34
I have data like this: something something_description, something2 something2_description, something3 something3_description... And now I need with PHP to get table as: <tr><td>something</td><td>something_description</td></tr> <tr><td>something2</td><td>something2_decription</td></tr> I don't know how many "something" and "something_decriptions" will it be so I need to set some loop. for now I have this code: $data = explode(',',$query); from that I will get array like: [0] => something something_description Now how can I put this into table? On net I found some examples for sorting array to