get part of string and insert to array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
LuaMadman
Forum Commoner
Posts: 35
Joined: Tue Jul 20, 2010 6:58 am

get part of string and insert to array

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: get part of string and insert to array

Post 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?
User avatar
LuaMadman
Forum Commoner
Posts: 35
Joined: Tue Jul 20, 2010 6:58 am

Re: get part of string and insert to array

Post by LuaMadman »

Celauran wrote:What about the formatting?
No, that will stay the same, it's only the values that is goning to change
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: get part of string and insert to array

Post 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?)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: get part of string and insert to array

Post by AbraCadaver »

That looks like a partial string of a serialized array. Where is the string coming from and have you mangled it somehow?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
LuaMadman
Forum Commoner
Posts: 35
Joined: Tue Jul 20, 2010 6:58 am

Re: get part of string and insert to array

Post 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.
User avatar
LuaMadman
Forum Commoner
Posts: 35
Joined: Tue Jul 20, 2010 6:58 am

Re: get part of string and insert to array

Post 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 =)
Post Reply