micalexander
7/3/2013 - 4:14 PM

python:Takes multiple strings and serializes it for php

python:Takes multiple strings and serializes it for php

#! /usr/bin/python


weeks = [
    	('Monday','Tuesday','Wednesday','Thursday','Friday'),
		('Monday','Tuesday','Wednesday','Thursday','Friday'),
		('Monday','Tuesday','Wednesday','Friday'),
		('Monday','Tuesday','Wednesday','Thursday','Friday'),
		('Monday','Tuesday','Wednesday','Thursday','Friday'),
		('Monday','Tuesday','Wednesday','Thursday','Friday'),
		('Monday','Tuesday','Wednesday','Thursday','Friday'),
		('Monday','Tuesday','Wednesday','Thursday','Friday'),
		('Monday','Tuesday','Wednesday','Thursday','Friday'),
		('Monday','Tuesday','Wednesday','Thursday','Friday')
		]

serialized_weeks = []

for week in weeks:

	pre_string = 'a:'+str(len(week))+':{'

	for (i, string) in enumerate(week):
		pre_string += 'i:'+ str(i) + ';s:' + str(len(string)) + ':"' + string + '";'

	pre_string += '}'
	serialized_weeks.append(pre_string)

for item in serialized_weeks:
	print item