Read and Split into Many variables

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
ChrisK
Forum Newbie
Posts: 9
Joined: Thu May 28, 2009 11:37 am

Read and Split into Many variables

Post by ChrisK »

I have a file named sku.txt with SKU number in each line. File may contains from 1 SKU to 100 SKU's. I need to read this file and split in to variables for every 10 SKU numbers.

if file has 5 sku numbers, then skuvar1 = 5 sku numbers
if file has 19 numbers, then skuvar1 = 10 numbers and skuvar2 = 9 numbers
if file has 35 numbers, then skuvar1= 10, skuvar2= 20, skuvar3= 10 and skuvar4= 5

Can someone help me how to implement it.

Appreciate your help.

Thanks
Chris
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Read and Split into Many variables

Post by AbraCadaver »

Probably better to use arrays:

Code: Select all

$skus = array_chunk(file('/path/to/sku.txt'), 5);
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.
ChrisK
Forum Newbie
Posts: 9
Joined: Thu May 28, 2009 11:37 am

Re: Read and Split into Many variables

Post by ChrisK »

Thank you for the Tip. I will test it out.
Post Reply