explode

Deep (infinite) split words using regex

狂风中的少年 提交于 2019-12-05 19:05:55
Lets say I have: $line = "{This is my {sentence|words} I wrote.}" Output: This is my sentence I wrote. This is my words I wrote. But, the regex should match deep and nested values and split these values, for example: $line = "{This is my {sentence|words} I wrote on a {sunny|cold} day.}"; Output: This is my sentence I wrote on a sunny day. This is my sentence I wrote on a cold day. This is my words I wrote on a sunny day. This is my words I wrote on a cold day. My first though was doing it over explode as in code below, but the result was not appropriate: $res = explode("|", $line); Advices?

Explode contents of a txt file into array

微笑、不失礼 提交于 2019-12-05 16:20:25
I´m having trouble exploding contents of a .txt file (structure below): 01Name 1 02whatever contents 03whatever contents ------------------- 01Name 2 02whatever contents 03whatever contents As you can see, the "delimiter" is "-------------------". Now, the question is: how to explode this file into an array, so I can search for a specific name and display that block´s contents? I´ve tried to explode like this: header("Content-type:text/plain"); $file = fopen("cc/cc.txt", "r"); while (!feof($file)) { $lot = fgets($file); $chunk = explode("-------------------",$lot); print_r($chunk); } fclose(

Split String Into Array and Append Prev Value

点点圈 提交于 2019-12-05 15:51:08
问题 I have this string: var/log/file.log I eventually want to end up with an array looking like this: Array => [ '1' => 'var', '2' => 'var/log', '3' => 'var/log/file.log' ] I currently have this: <?php $string = 'var/log/file.log'; $array = explode('/', $string); $output = [ 1 => $array[0], 2 => $array[0]. '/' .$array[1], 3 => $array[0]. '/' .$array[1]. '/' .$array[2] ]; echo '<pre>'. print_r($output, 1) .'</pre>'; This feels really counter-intuitive and I'm not sure if there's already something

Remove part of an NSString

感情迁移 提交于 2019-12-05 12:37:24
I have an NSString as follows: <img alt="996453912" src="http://d2gg0uigdtw9zz.cloudfront.net/large/996453912.jpg" /><a href="http://www.dealcatcher.com/shop4tech-coupons">Shop4Tech Coupons</a> I only need the first part (before the <a href part), and I cannot figure out how to remove the second part. I have tried a ton, but it has not worked. Use something like: NSRange rangeOfSubstring = [string rangeOfString:@"<a href"]; if(rangeOfSubstring.location == NSNotFound) { // error condition — the text '<a href' wasn't in 'string' } // return only that portion of 'string' up to where '<a href' was

Calling PHP explode and access first element? [duplicate]

妖精的绣舞 提交于 2019-12-04 22:20:30
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? Array dereferencing is not possible in the current PHP versions (unfortunately). But you can use list [docs] to directly assign the array elements to variables: list($first, $last) = explode("#", "1234#5678"); UPDATE Since PHP 5.4 (released 01-Mar-2012) it supports array dereferencing . Most likely PHP is

Hive-explode[列转行]关键字使用

不羁岁月 提交于 2019-12-04 22:08:17
本文讨论 Hive explode 关键字使用, 并使用一个简单案例来验证结果. Hive 支持 array 和 map 类型, 但是如何统计 array 或 map 里的值, 一直没有找到好的方法. Pig 有行转列关键字 flatten. 查阅了很多 Hive 资料, 找到了 explode 关键字. 谨以此例来验证 Hive explode 功能. hive> create table if not exists explode_array > ( > userId string, > userName string, > tags array<string> > ) > ROW FORMAT DELIMITED > FIELDS TERMINATED BY '\t' > COLLECTION ITEMS TERMINATED BY ','; OK Time taken: 0.942 seconds 数据样例: 00001 zhzhenqin 80,90 00002 hello java, 女 00003 world java,python,90 查询: hive> select * from explode_array limit 10; OK 00001 zhzhenqin ["80","90"] 00002 hello ["java"," 女"] 00003 world

Possible grouping of words

守給你的承諾、 提交于 2019-12-04 14:03:36
问题 This is not homework: Came across this scenario while working on PHP String Differences and Dynamic Restrictions Given a string of n words how to distribute them into m groups without altering the word sequence? Example 1: String: "My name is SparKot" Groups: 2 (string is split in to two strings) Possible groups will be: ('My', 'name is SparKot'), ('My name', 'is SparKot'), ('My name is', 'SparKot') with the same string Example 2: String: "My name is SparKot" Groups: 3 (string will be split

explode two-item-list in array as key=>value

天涯浪子 提交于 2019-12-04 09:30:59
问题 I'd like to explode a multi-line-string like this color:red material:metal to an array like this $array['color']=red $array['material']=metal any idea? 回答1: Use explode(), you can use a regexp for it, but it's simple enough without the overhead. $data = array(); foreach (explode("\n", $dataString) as $cLine) { list ($cKey, $cValue) = explode(':', $cLine, 2); $data[$cKey] = $cValue; } As mentioned in comments, if data is coming from a Windows/DOS environment it may well have CRLF newlines,

PHP. How to explode •

二次信任 提交于 2019-12-04 07:05:50
问题 I have some text: text,text • text.text • text:text I need array('text,text','text.text','text:text); How do I explode •? WORK!!! need: $txt = html_entity_decode($txt); $textArray = explode("•",$txt); print_r($textArray); 回答1: Try that: $str = "text,text • text.text • text:text"; $new_arr = explode ('•', $str); 来源: https://stackoverflow.com/questions/33959444/php-how-to-explode

php - explode string at . but ignore decimal eg 2.9

核能气质少年 提交于 2019-12-04 05:39:39
问题 Currently I am exploding a string at . and it works as I like. the only issue is that is also explodes when the . occurs as a decimal point. Is there a way of excluding decimal points from the explode function? My current setup: As you can see it is exploding at . between the two numbers $String = "This is a string.It will split at the previous point and the next one.Here 7.9 is a number"; $NewString = explode('.', $String); print_r($NewString); output Array ( [0] => This is a string [1] =>