Sorry, I'm a n00b to web languages. I'm trying to upload a CSV file, parse the second and seventh columns, and output it to the Google Graphs API. This is my first ever time trying to do anything with PHP, so, a example would be nice for me to analyze, but, I can try to figure out everything with documentation as well.
Thank you so much for help in any way.
here's how you can upload a file with PHP: http://de3.php.net/move_uploaded_file
Parsing a CSV file is easy:
$csv = file('path/to/file.csv');
foreach ($csv as &$current) {
$current = explode(';', $current);
}
If you then loop through $csv you have the second and seventh column in $csv[$iterator][1] and $csv[$iterator][6].
I haven't used Googles Graph API, so I can't help you with that.
If you're not married to google graphs, try highcharts. I've used it on several occasions and really like it. They have some tutorials and good sample code to look at, too.
Check the other response for parsing a CSV file; it's spot on.
There is a component designed to easily implement the graph by uploading the CSV file: Graph from CSV file
Related
I want to convert any pdf,docx,doc file into html code using php. with same style as in pdf. I am not getting proper solution.
Config::set('pdftohtml.bin', 'C:/poppler-0.37/bin/pdftohtml.exe');
// change pdfinfo bin location
Config::set('pdfinfo.bin', 'C:/poppler-0.37/bin/pdfinfo.exe');
// initiate
$pdf = new Gufy\PdfToHtml\Pdf($item);
// convert to html and return it as [Dom Object](https://github.com/paquettg/php-html-parser)
$html = $pdf->html();
Not working for me.
I had a similar problem and i found a github that i used with word docs. It worked fairly good then but i havent tested it of late. try it.
https://github.com/benbalter/Convert-Word-Documents-to-HTML
I think that this post could help you in a first time. With this one, you'll be able to convert any pdf into HTML code using PHP.
After this, you can use the help provided by this post to convert .doc and .docx to PDF using PHP.
I think that you can now built a function for each document extension that you want to convert into HTML.
Good luck.
I've come across a web service which presents an API for converting documents. I haven't tested it very thoroughly but it does seem to produce decent results at converting Word to HTML:
https://cloudconvert.org/
I have an excel file with 3 columns, "First name", "Last name", "email" and about 700 entries (rows). I also have a website with a form for first name, last name and email. Obviously I don't want to type out all 700 entries manually. Is there a way to get these columns from excel and enter them into the online form? Perhaps using visual basic/php or any other alternative. If such code already exists then it would be great if somebody could show me. If not, then it would be appreciated if somebody could give some advice on how to approach this. Thanks!
PHP has a CSV method, you can convert/save your excel file to csv and process if using PHP.
Reading the File in PHP
Example 1
How to create an array from a CSV file using PHP and the fgetcsv function
$file = fopen('youruploadedfile.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
// each line of the array
print_r($line);
}
fclose($file);
Example 2
https://www.w3schools.com/php/func_filesystem_fgetcsv.asp
$file = fopen("youruploadedfile.csv","r");
while(! feof($file))
{
print_r(fgetcsv($file));
}
fclose($file);
check out https://www.w3schools.com/php/func_filesystem_fgetcsv.asp
Definition and Usage
The fgetcsv() function parses a line from an open file, checking for CSV fields.
The fgetcsv() function stops returning on a new line, at the specified length, or at EOF, whichever comes first.
This function returns the CSV fields in an array on success, or FALSE on failure and EOF.
Selenium
Selenium is a tool to automate user interface testing. It helps with testing your application against the browser
Take a look at the web driver https://github.com/facebook/php-webdriver
There is also varied information on how to's on SO.
How to use Selenium with PHP?
Its easier to do this in python/java. Excel is just used to store the list of input values but to actually input it into a webpage using an automated technique you will need to read about webscraping.
Things like BeautifulSoup (a package in python) and Selenium (a java package) can be used for this purpose. You will have to read about them and maybe ask questions to people who know python/java not excel/vba experts.
Here is one link that can get you started
How can I input data into a webpage to scrape the resulting output using Python?
Edit:
I found one link which could help in doing it through VBA but you need to tell us which website only then can someone help you further
Input text into html input box using vba
I have been trying to find a simple way to create OpenOffice calc files with no success.
I have tried:
openTBS - Seems to work writing an xml and a template file but can't find anything about how the xml file format.
Ods php generator - I tried this one as it provides clear examples, but when I copy the files to my server I always get corrupted files
Php doc writer - Tried an example and got an sxw file. I don't even know what that is
ODS-PHP - No documentation, only one example for creating 4 cells
Everything looks old, stalled and undocumented. ¿Any suggestion?
I have used opentbs successfully.
You can generate both excel and calc files. It also nice that you can "reuse" your html implementation so to speak.
Maybe this thread could get you going http://www.tinybutstrong.com/forum.php?thr=3069
Do the html version first.. then edit for calc/excel
Spout from Box works well enough for me. There are some missing features but it is simple to use, has a fluent API, and has no dependencies (it supports composer but you can use it standalone and its dependency graph has zero depth 😉 ).
Here's my "array of objects to ODS" pipeline, using Spout:
(I'm not using their recommended use import because all this code fits in a much larger file that I didn't want to contaminate and the $factory pattern looks cleaner to me anyway)
$factory = 'Box\Spout\Writer\Common\Creator\WriterEntityFactory';
$factory::createODSWriter()
->openToBrowser('filename.ods')
->addRow($factory::createRow([
$factory::createCell(__('Heading 1')),
$factory::createCell(__('Heading 2')),
$factory::createCell(__('Heading 3')),
]))
->addRows(array_map(function($row) use ($factory) {
return $factory::createRow([
$factory::createCell($row->first_val),
$factory::createCell($row->second_val),
$factory::createCell($row->third_val),
]);
}, loadDataFromSomewhere()))
->close();
I have this code:
$book = new Spreadsheet_Excel_Writer();
$book->send('book.xls');
$report =& $book->addWorksheet('sheet');
$i = 0;
while ($i<145){
$report->write($i, 0, 'dsbajk_'.$i);
$i++;
}
$book->close();
This produces a file of 6 KB but when I tried to open it in Excel there is an error with the file, something like: Excel found content that couldn't read and is possible that some data was lost. (I can't write the exact message because is in Spanish).
If I change 145 to 144 (or less) in the loop no messages is displayed, so I think is a problem with the buffer or size of the text. I need to replace the while loop with a db query with more data so is important this works well.
I tried this in other server and I didn't have this problem, so maybe is something with the config.
I apreciate any help.
As Marc B said switch to PHPExcel is a good decision if you're starting a new project. It supports xlsx and other modern formats as well as the traditional xls. It also has more options and is easy to install and use.
I used PHPExcel in my project and I'm pretty happy. :)
I've written a framework (it's been a year) which will render AS3 code as HTML5
I want to reach into a swf and parse the guts into my framework so that you can upload an AS3 swf and get the HTML5 equivalent back.
Any ideas on how to parse a swf/fla using php?
** edit **
As a reference, google does something similiar to this. However, swiffy only parses AS2 code.
** edit 2 **
For further clarification, I only want to be able to parse a swf for layout props and actionscript. I've got the rest figured out.
Take a look at SWFTools - that can dump the code out of SWFs apparently, and has source code, though you could use the command line utilities from PHP and parse the output to get the actionscript sections out. God knows what you will do with it then.
https://github.com/iborodikhin/php-swiffy/
use this lib and implement like this
require_once('php-swiffy-master/vendor/autoload.php');
$swiffy = new Swiffy\Client();
$html = $swiffy->convert("test.swf");
$myfile = fopen("test.html", "w");
if(!empty($html)){
fwrite($myfile, $html);
fclose($myfile);
}