Complex data splitting - php

I am reading excel files through php, the contents are to be displayed in a table on web
I read this data in range A1 to D1 is one data and it is to be presented in this format
The data
is different,
in every,
cell.
This data is to be <br/> line breaked based on strlen (This is a single string is different, in every, cell. Line one The data is heading)
So line breaks are made based on , but max data has to fit in single line
So how can I count strlen to each , so that I can echo if the data can fit in single line or else a line break is made after ,
The data
is different,
in every, cell.

Use strpos() with an offset in a loop in order to find the commas. After finding the first comma, use this position as the new offset for finding the next comma.

Have your tried the PEAR Excel Package(s)? It Simplifies things (reading/writing .xls files)

The str_getcsv() function added in PHP 5.3 may be of use to you.
If not, surely you could just explode(',', $string)?

Related

Getting the sum of an excel column without getting subformula using PHPExcel

I was wondering if I can get the sum of an excel column, without getting the subformula for each item category(Tort and nach).
Take note that there are times there will be an additional item and will be added to the category; meaning I cannot specify the cell value (e.g, SUM(G12:G18) + SUM(G21:G26)).
Is there any way to do this using PHP Excel?
try: =SUM(G12:G18,G21:G26)
I have a diffent excel language, where I have to use a semi-colon in stead of a comma in the formula

Replacing arrays in a loop in PHP, performance issue

what I do is
query (count) of rows from DB
replace strings in them
write it in .csv
When 150 rows are selected in the first step, around 20sec. are needed to finish the script (csv is ready). If I bypass the second step, nothing replaces, the export is ready for ~2sec.
To replace I defined two not associative arrays: array $replace and array $rwith each with 30 elements.
Then:
str_ireplace($replace, $rwith, $value);
Probably str_replace (case sensitive) will speed the things up a little, but my goal is under 5s. What can you suggest to optimize this?

PHPExcel - formatting a column as percent not applying

I am using PHPExcel to write an entire array to a sheet and a couple of my columns need to have the value in every cell displayed as a percent (ie with the percent sign).
My problem is that when I try to format column G as a percentage with this code:
$format_percent = array('code' => PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00);
$objWorksheet->getStyle("G2:G".$rc)->applyFromArray($format_percent);
The resulting file has all cells in column G still with the "General" number format...not formated as a percent as I had hoped.
NOTE: the $rc variable is storing the row count
Any ideas? Thanks in advance.
Think I figured it out. I was trying to apply the formatting to the whole column at once. That doesn't seem to work. I thought it would because I CAN apply formatting like Bold to the text or and entire row at once. However, when I did a test and applied the percent formatting to one cell, it worked fine. So now I have just decided to loop over all of my cells in my column and apply the formatting one at a time.

php array phone number fields stored as int

I had a MySQL table with some user data, which I needed to correct and migrate to a new MySQL table. I exported the table using "Export to PHP Array plugin for PHPMyAdmin" from "Geoffray Warnants" and it returned a (PHP) array.
One of the fields contains a telephone number. Now some of the entries have been exported as string. However, some of the entries have the telephone number represented as an integer. When I try to read the number, it returns something like:
4.36991052022E+12
when it should be:
4369910520219
I suppose the integer value is too big, so that must be the problem. (that's the reason for the E+12)
I have close to 300 entries and there is no way I can start writing quotes in front and end of the number manually, since I also have a fax field.
Most recently, I tried (with help of demo sublime text 2) to cast the number by writing (string) in front of it - it doesn't work.
I'm kind of helpless now and ask for your help. What can I do?
Please take a look at this question, which should answer yours:
Convert a big integer to a full string in PHP
Since I didn't have the time to get trough the "complicated" process of installing the GMP library, I decided to make it old-skool and just put double quotes ("") in front of every phone number value no matter if is was a string or a "big integer" and remove (single) quotes from the final string.
Thanks to Sublime Text 2!
So i had:
array(..., 'phone'=>' 43 664 1000383', ...);
and
array(..., 'phone'=>4369910520219, ...);
Search for and Find All 'phone'=> and add afterwards "
Then search for (in my case) ,'fax'=> and add beforehand "
The for every string
preg_replace("/\'/i", "", $user["phone"]);
Thanks though for the library. I might actually use it someday. ;)
Greetings,
Joseph

PHP, find exact value from mysql arranged data

I have a data in My-Sql column like this
T_interest
1,14,49,145,203,302
It represents each value for personal interest keywords.
I tried to extract the value and distinguish whether it has the value or not for the checkbox.
if(strstr($u_interest['u_interest'], ','.$row['i_idx'])):
$selected = 'checked';
here is the php command that I use right now.
but it doesn't extract exact value from the database.
Let's say I want to check if the data has 14 number or from this user table
T_interest
1,14,49,145,203,302
and if I use above command it tells me that a user has two values.
14,145
It looks like PHP strstr command tells me two values because these two have 14 number.
So, can you help me why this is happening?
If you want more php lines I can post them.
Explode it into an array, this way you get the individual values.
explode(",",$t_interest["u_interest"]);
Then you can test for equality much easier.
You really need to read up on database normalization. A properly normalized design would make this problem moot.
As for your question, since you're forced to use string operations, you'll have to check for multiple different cases:
1) the number you want is at the START of the string
2) the number you want is at the END of the string
3) the number you want is the ONLY number in the string
4) the number you want is in the MIDDLE of thee string:
SELECT ...
WHERE
(T_Interest = 14) OR // only number
(T_Interest LIKE '14,%') OR /// at the begnning
(T_Interest LIKE '%,14') OR // at the end
(T_Insertest LIKE '%,14,%') // in the middle

Categories