Page 1 of 1

get part of string and insert to array

Posted: Thu Nov 18, 2010 9:51 am
by LuaMadman
I got this long string.

Code: Select all

,4320,,931,simple,a:1:{s:15:"info_buyRequest";a:3:{s:4:"uenc";s:56:"aHR0cDovL2JldGEudGVsbHlvdXJmcmllbmRzLnNlL2luZGV4LnBocC8,";s:7:"product";s:3:"931";s:3:"qty";i:1;}},,GPS2,Another Test GPS,,103.0000,0,2,0,79.2,,,79.2,79.2000,25.0000,39.6000,39.6000,39.6000,,206.0000,158.4000,79.2000,39.6000,158.4000,a:0:{},0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,,2
I want to get the GPS2,Another Test GPS,,103.0000,0,2,0,79.2,,,79.2,79.2000,25.0000,39.6000,39.6000,39.6000,,206.0000,158.4000,79.2000,39.6000,158.4000
and insert each value in to a array.
But I got no clue how to do that.
ALL values of the entire string could/will be diffrent each time i call the function to get the string.
I figuer, as long as I can seperate that string, I can use explode to get the values to the array.

Re: get part of string and insert to array

Posted: Thu Nov 18, 2010 10:29 am
by Celauran
LuaMadman wrote:ALL values of the entire string could/will be diffrent each time i call the function to get the string.
What about the formatting?

Re: get part of string and insert to array

Posted: Thu Nov 18, 2010 12:14 pm
by LuaMadman
Celauran wrote:What about the formatting?
No, that will stay the same, it's only the values that is goning to change

Re: get part of string and insert to array

Posted: Thu Nov 18, 2010 12:53 pm
by Celauran
You can extract the desired substring using a combination of substr() and stripos(), then. Are null values possible? Could two currently adjacent commas ostensibly have a value between them at some point? (ie. are the commas field delimiters?)

Re: get part of string and insert to array

Posted: Thu Nov 18, 2010 1:22 pm
by AbraCadaver
That looks like a partial string of a serialized array. Where is the string coming from and have you mangled it somehow?

Re: get part of string and insert to array

Posted: Fri Nov 19, 2010 1:37 am
by LuaMadman
It's a complete string. To get it I used:

Code: Select all

	foreach ($this->getQuote()->getAllItems() as $item) {
		$orderItem = $convertQuote->itemToOrderItem($item);
		$orderline .= $orderItem . "\n\n";
$orderItem = the entire string I posted

It's for magento and that's get's me the string.
I been looking for a way to get the quantity of the order, and so far that's string is all I found.

Re: get part of string and insert to array

Posted: Fri Nov 19, 2010 1:43 am
by LuaMadman
Clearly I was to tierd yesterday... And did not think of the obvios...

Code: Select all

		$qty = $item->getQty();
		$prodId = $item->getProductId();
		$product = Mage::getModel('catalog/product')->load($prodId);
		$sku = $product->getSKU();
$qty gives me what i need from the actual order.
Everything else I can get from $product

Thank you. You all been very helpfull =)