Converting Digits into string - php

1) I have been working on fetching data from an excel sheet i can see on a cell written Oct-10 but when i select it i see 10/31/2000 on fx column right at top ,when i fetch data from the .xls sheet using http://phpexcel.codeplex.com library version number 1.7.3 ,it is returning float("40482") ,
can any body tell how to convert it to either 10/31/2000"/"Oct-10 all the cells other than this one are reading correctly so there is no error in code.
2) Also Please tell how can i get a better tutorial for this library as one provided on this site is not very helpful or i am using wrong library.
thanks in advance

See answer to this question Days since 1900
or read section 3.2 (and specifically 3.2.3) in the not very helpful "PHPExcel Function Reference Developer Documentation" which describes exactly how to convert between Excel dates and PHP dates (or PHP date/time objects).
The function you're after is:
$PHPdateValue = PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
or
$PHPdateObject = PHPExcel_Shared_Date::ExcelToPHPObject($excelDateValue);
There are links to a number of tutorials in a variety of languages on the documents section of the PHPExcel website. And in addition to the documentation, there's plenty of code examples in the /Tests subdirectory of the distribution
Example of returning a PHP date/time object:
include 'PHPExcel.php';
$excelDateValue = 40482.0;
$dateObj = PHPExcel_Shared_Date::ExcelToPHPObject($excelDateValue);
echo $dateObj->format('Y-m-d H:i:s');
displays
2010-10-31 00:00:00

Related

PHP Spreadsheet - Date not filtering

when using PHP spreadsheet i have the date set in the correct format but when opening in excel i am unable to filter dates by month / year etc. i have to click on each date select the formula bar and press enter. this then allows me to filter the date.
how can i set phpspreadsheet to do set this correctly ?
i have been searching google for a solution. the limited results i have found seem to point to the same way i have implemented this
Any suggestions?
Thanks

Reading date from Excel using PHP giving one day more

I am trying to read dd/mm/yyyy date from Excel. It is behaving very inconsistently. At times it adds one day more to the actual date in the cell and at times give the correct date.
The code:
$pdiDate_key = array_search('PDI Date',$excel->sheets[0]['cells'][1]);
Based on your code example, I'm going to guess that you're using PHP-ExcelReader to retrieve the dates from Excel. If I'm right, then, well, there is a known error in Excel that PHP-ExcelReader doesn't handle. The "bug" report is here:
SourceForge.net: PHP-ExcelReader: Detail: 2388545 - Wrong Date
The comments at the bottom of that page include code for a function to fix the error.

How do I work out which shapefile (suburb) contains a given lat-lon point in PHP

I only have access to PHP5 (no PostGIS)
I have a bunch of suburb shapefiles, and a few events with lat-lon points. I've zero experience with shapefiles.
What is the best way to check which shapefiles contain these lat-long points (using only PHP)?
Do I convert the shapefiles to a lat-long polygon and use standard polygon-point intersection equation?
Or is these some awesome PHP library for loading/working with Shapefiles?
Each shapefile consists of 3 parts, shp,shx,dbf. The shp file contains the geometry, shx is an index to help access the shp, the dbf is plain old dbase file that contains data for each record.
You can extract the bounding box from the shp file as follows,
$handle = fopen("path/to/file.shp","rb");
fseek($handle, 36);
$min_x = unpack("d",fread($handle,8);
$min_y = unpack("d",fread($handle,8);
$max_x = unpack("d",fread($handle,8);
$max_y = unpack("d",fread($handle,8);
// Note, this code will only work on a little-endian machine
// You'll need to do a byte swap on big endian systems
Then you can test to see if a given event lies in the shapefile's bounding box.
if (($event_x >= $min_x) && ($event_x <= $max_x)
&& ($event_y >= $min_y) && ($event_y <= $max_y))
You can put this is a loop and get a subset of your shapefile that overlap with a given event. This doesn't mean you event is inside a polygon in a given shapefile, but it'll get you close. If you need an exact solution you'll have to extract the polygons and do a point in polygon test.
Disclaimer: Consider the above code pseudo code, I don't know php, so there are probably some bugs. Also, If you can switch to python things get a lot easier, there are existing libraries that provide shapefile parsing and spatial indexing, so you can determine exactly which polygons a point intersects with in a highly efficient manner.
Ref: ESRI Shapefile Whitepaper, http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf
To work with shapefiles, I suggest loading them into a database with spatial relations, and using the spatial relation capabilities of the database.
I personally use PostgreSQL with PostGIS extension for this. It has a utility for converting the shapefiles into an SQL insert. Then you can put your point into WKT (well known text) and query the database for what shapefile(s) it intersects with.
I do not believe php itself has any built in functions for dealing with GIS.
EDIT- Damn - I'm sorry, I didn't see the (no PostGIS) part until after the post. You might be able to convert your polygons to wkt and use a polygon-point intersection.
I know this question is quite old, but as a service to the community and future users looking for similar functionality in native PHP, I'd like to point out that my PHP Shapefile is a free and open source PHP library that can read and write any ESRI Shapefile, without any third party dependency.
Link to GitHub project: https://github.com/gasparesganga/php-shapefile

How do I make a RTF (Rich Text Format) document through PHP from a form submission?

I'm searching on Google but most of the results I'm getting have these complicated software being used. I'm choosing to use RTF because it's the easiest to code straight through PHP and did it before but forgot the website I was getting help from.
could someone give me a brief summary of how to replace insertable variables in a pre-written rtf document with mysql form data using php? I have variable insertion locations marked in my rtf document with $variable1, $variable2 etc, which corresponds to the variable names in my mysql table.
Or could someone provide me with a link to an already existing tutorial on it please?
edit: and if it uses a prewritten software, it has to be free.
Basic rtf with replace: http://www.tuxradar.com/practicalphp/11/3/0 just really depends on how complex your pre-written rtf is
$rtf=<<<RTF
{\rtf1
\b [TITLE] \b0\par
\b [MESSAGE] \b0\par
}
RTF;
$rtf = str_replace('[TITLE]',$valueTitle,$rtf);
$rtf = str_replace('[MESSAGE]',$valueMessage,$rtf);
or you could build an rtf document as the data is retrieved, much like you would with html.
or use a class like: http://www.phpclasses.org/package/1805-PHP-Create-RTF-documents-from-HTML.html
Try this http://www.daniweb.com/web-development/php/threads/320472
I couldn't find the rtf tutorial I was looking for so just decided to use pdf, which is already well explained here in this stack overflow question.
How to make a pdf file using PHP

What does wikipedia use for text and revision diffs

I'm trying to take 2 versions of text (10 pages long) and compare the 2 to produce the difference. I know Wikipedia has a similar feature to compare revisions. Does anyone know what they use? I'm hoping they're using a php-driven solution.
There is an implimentation of diff in php. I haven't used it but it's a start. There is also something called PHP inline diff that you can check out

Categories