explode

How to explode URL parameter list string into paired [key] => [value] Array? [duplicate]

家住魔仙堡 提交于 2019-12-02 13:52:01
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Parse query string into an array How can I explode a string such as: a=1&b=2&c=3 So that it becomes: Array { [a] => 1 [b] => 2 [c] => 3 } Using the regular explode() function delimited on the & will separate the parameters but not in [key] => [value] pairs. Thanks. 回答1: Use PHP's parse_str function. $str = 'a=1&b=2&c=3'; $exploded = array(); parse_str($str, $exploded); $exploded['a']; // 1 I wonder where you get

Explode does not work with multilpe commas inside the string [closed]

 ̄綄美尐妖づ 提交于 2019-12-02 13:42:28
I try to find the answer here and in Google but no luck! Why it does not work when I try to explode the string? $Text = "brazil,banks,home,,uk,,,,test,financial times,.,ipad,,banks,,Two words,,"; $Text_Array = explode(",",$Text); $Text_Array = array_filter($Text_Array); print_r($Text_Array); I would like to have all my tags divide by ONE comma and remove any space and duplicate tags. I would like this result: "brazil,banks,home,uk,test,financial times,ipad,Two words"; Please, can you help me to achieve this? If you want to remove any space and duplicate tags then you need to also add array

Convert a string into list of arrays

一曲冷凌霜 提交于 2019-12-02 13:38:59
How do I convert a REQUEST string into arrays in a list like the following? $_REQUEST["InventoryData"] == sku=qty&234444=11&ShirtBig=111&ShirtSmall=101&empty=0 Array ( [0] => sku [1] => qty ) Array ( [0] => 234444 [1] => 11 ) Array ( [0] => ShirtBig [1] => 111 ) Array ( [0] => ShirtSmall [1] => 101 ) Array ( [0] => empty [1] => 0 ) This is a modification of "MASS UPDATE STOCK LEVELS IN MAGENTO – FAST" script for updating using a client side submission of data. $result = array(); parse_str($_REQUEST['InventoryData'], $data); foreach ($data as $key => $value) { $result[] = array($key, $value); }

PHP split/explode string

混江龙づ霸主 提交于 2019-12-02 13:24:50
问题 I would like to split/explode a string in PHP. The string looks like this: <strong>Label</strong><p>Value</p> With this result: array( '<strong>Label</strong>', '<p>Value</p>' ) How can I do this? 回答1: You can do it like this: $string = "<strong>Label</strong><p>Value</p>"; $pos = strpos($string,'<p>'); $array = array(); $array[] = substr($string, 0,$pos); $array[] = substr($string,$pos); Or using preg_match: preg_match('%(.*g>)(.*)%',$string,$array); //$array[1] = '<strong>Label</strong>' //

Function resembling the work of Explode in MySQL

岁酱吖の 提交于 2019-12-02 11:35:54
问题 Is there any function in MySQL to explode data of a column and then retrieve it? Like if a column data is P:12 , then can the data be exploded on ':' and then read? 回答1: Here are many discussion about the SPLIT problem in mysql : http://dev.mysql.com/doc/refman/5.0/en/string-functions.html 回答2: You can write a Split function in MYSQL check this link From the Link CREATE FUNCTION SPLIT_STR( x VARCHAR(255), delim VARCHAR(12), pos INT ) RETURNS VARCHAR(255) RETURN REPLACE(SUBSTRING(SUBSTRING

exploding a string using a regular expression

早过忘川 提交于 2019-12-02 11:04:24
问题 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,

Grab the video ID only from youtube's URLs

僤鯓⒐⒋嵵緔 提交于 2019-12-02 10:09:35
问题 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

How to retrieve imploded images path in database to view in code igniter

落花浮王杯 提交于 2019-12-02 08:45:39
I am trying to save the multiple images path in database and upload images in root's upload/images[directory]. I have done it and its working. Images name are saved in database and and the image files are being uploaded. I just did save the images name by imploding. Now I need to explode that image in view. How can i do that? I have tried the following code in view and its not working. <?php foreach ($products as $p): ?> <tr> <td><?php echo $p['id']; ?></td> <td><?php echo $p['product_name']; ?></td> <td><?php echo $p['product_price']; ?></td> <td><?php echo $p['produce_description']; ?></td>

Exploding a string twice

不羁的心 提交于 2019-12-02 06:53:56
问题 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";

Function resembling the work of Explode in MySQL

时间秒杀一切 提交于 2019-12-02 06:09:58
Is there any function in MySQL to explode data of a column and then retrieve it? Like if a column data is P:12 , then can the data be exploded on ':' and then read? Here are many discussion about the SPLIT problem in mysql : http://dev.mysql.com/doc/refman/5.0/en/string-functions.html You can write a Split function in MYSQL check this link From the Link CREATE FUNCTION SPLIT_STR( x VARCHAR(255), delim VARCHAR(12), pos INT ) RETURNS VARCHAR(255) RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), delim, ''); Usage SELECT SPLIT_STR(string,