explode

Exploding a string twice

怎甘沉沦 提交于 2019-12-02 06:04:13
I have a string composed like this: 87||1|nuovo#88||4|#209|||#89|||#41||1|#5|||#3||1|116#20|||#13||3|#148||| The pattern is: Id1|Mq1|Q.ta1|Tipo1#Id2|Mq2|Q.ta2|Tipo2#Id3|Mq3|Q.ta3|Tipo3 and so on... Basically each item has 4 attributes separated by "|" and each item is separated by "#" I'd need to explode the string to have single variables for each item's attributes. As for now I'm here: <?php $str = "87||1|nuovo#88||4|#209|||#89|||#41||1|#5|||#3||1|116#20|||#13||3|#148|||#36|||91#29|||68"; $caratteristica = print_r (explode("#",$str)); ?> Which gave me this result: Array ( [0] => 87||1|nuovo

How to get an array value after explode?

≯℡__Kan透↙ 提交于 2019-12-02 05:37:11
I have passed a value from one page to another in array. I can extract first two vars by explode but I can't get the third value which is formed in an array out. This is my array: $user_rate=$_POST['user_rate'];//15000|ss|Array list($total,$promo,$rate)=explode("|",$user_rate); So I get: $total=15000; $promo=ss; $rate=Array; While Array comes from the previous page by looping the daily rate and put in an array. And I need to know what each rate is, so I wrote: foreach($rate as $val){ echo "$val<br>"; } But it shows nothing. How can I get this? Updated : This is the code before the var is sent.

PHP: How to turn a string that contains an array expression in an actual array?

寵の児 提交于 2019-12-02 03:13:43
I have an array of user inputs ($atts) as key=>value pairs. Some of the values could be written as an array expression, such as: 'setting' => 'array(50,25)' In those cases, I would like to convert the array expression contained in that string into an actual array. So the output would be something like: $atts = array( 'setting' => array(50,25), 'another' => 'not written as an array expression' ) Written logically, the code would be: For each key=>value pair in the array $atts... if the value is a string formatted as an array expression... explode that value into an array. Anybody know how I

exploding a string using a regular expression

妖精的绣舞 提交于 2019-12-02 03:06:50
I have a string as below (the letters in the example could be numbers or texts and could be either uppercase or lowercase or both. If a value is a sentence, it should be between single quotations): $string="a,b,c,(d,e,f),g,'h, i j.',k"; How can I explode that to get the following result? Array([0]=>"a",[1]=>"b",[2]=>"c",[3]=>"(d,e,f)",[4]=>"g",[5]=>"'h,i j'",[6]=>"k") I think using regular expressions will be a fast as well as clean solution. Any idea? EDIT: This is what I have done so far, which is very slow for the strings having a long part between parenthesis: $separator="*"; // whatever

Grab the video ID only from youtube's URLs

夙愿已清 提交于 2019-12-02 02:55:24
How can I grab the video ID only from the youtube's URLs? For instance, http://www.youtube.com/watch?v=aPm3QVKlBJg sometime the URLs contain other information after the 'v' like http://www.youtube.com/watch?v=Z29MkJdMKqs&feature=grec_index but I don't want the other info, just video ID. I only can think of using explode, $url = "http://www.youtube.com/watch?v=aPm3QVKlBJg"; $pieces = explode("v=", $url); but how to clean up the URLs like this? http://www.youtube.com/watch?v=Z29MkJdMKqs&feature=grec_index You should never use regular expressions when the same thing can be accomplished through

explode() function using GROUP SEPARATOR

情到浓时终转凉″ 提交于 2019-12-02 02:40:22
问题 As per find through MySQL GROUP_CONCAT escaping this I have use GROUP_CONCAT SELECT `topic_response`.`response`, GROUP_CONCAT(`comment` SEPARATOR 0x1D ) AS `comment`, `topic_response`.`add_date` FROM `topic_response` WHERE (topic_id = 286) AND (`comment` IS NOT NULL) GROUP BY `response` ORDER BY `add_date` desc Then my output is properly separated but I don't know how to explode() it. explode("0x1D", $comment) or explode("\0x1D", $comment) This does not work. 回答1: If you still want to use

PHP: do an ORDER BY using external data?

五迷三道 提交于 2019-12-02 02:22:18
问题 Ahoy all! Long story short with this one if you don't mind lending a hand to this novice PHPer. :) I have a database field called "Categories" that has this stored: Fruit, People, Place, Animals, Landscape I also have a separate table in the DB that has items with these category names in the fields for each item. Right now, the script (i am trying to fork it a bit) uses: SELECT DISTINCT(type), type FROM the_categories ORDER BY type ASC in order to display a list of all categories available.

ECShop出现Strict Standards: Only variables should be

我的未来我决定 提交于 2019-12-02 00:30:50
今天安装ecshop的时候最上面出现了一个错误提示:Strict Standards: Only variables should be passed by reference in F:\www.xxxx.com\cls_template.php on line 418 解决办法: 打开cls_template.php文件中发现下面这段代码: $tag_sel = array_shift(explode(' ', $tag)); 忘记说了,我的PHP版本是5.4.19,PHP5.3以上默认只能传递具体的变量,而不能通过函数返回值传递,所以这段代码中的explode就得移出来重新赋值了 $tagArr = explode(' ', $tag); $tag_sel = array_shift($tagArr); 这样之后顶部的报错没掉了,左侧和底部的报错还需要去ecshop的后台点击清除缓存才能去除。 来源: oschina 链接: https://my.oschina.net/u/194611/blog/599919

Handling new lines in php

孤街醉人 提交于 2019-12-01 20:40:50
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 and use: $br = nl2br($string,true); $array = explode("<br />", $br); The reason why I use nl2br is I

PHP array and implode with blank/null values

我与影子孤独终老i 提交于 2019-12-01 17:12:39
问题 I have a array which i generated by values in a database, the example is below: $addressarray = array($results['client']->client_city, $results['client']->client_county, $results['client']->client_postcode); The values are entered by the user using a from, the above array works and the correct values are placed into it, however sometimes the user may not enter the clients county, so therefore $results['client']->client_county may be blank. I call the array with this. $address = implode("\n ",