read the contents from pdf and neatly align the details - php

How to read the contents from pdf and neatly align the details in html page using php
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
fclose($handle);
print $contents;
But some unwanted symbols are coming

Best way to use PDF2TEXT:
//Include here
include('class.pdf2text.php');
$var = new PDF2Text();
//Set PDF
$var->setFilename('YOUR PDF.pdf');
$var->decodePDF();
//Desired Output
echo $var->output();

Related

How to convert Excel file to text file in php?

I want to convert an excel file to a text file. I have tried this code but it doesn't work:
$destination = 'products.xls';
$section = file_get_contents($destination);
$File = "file.txt";
$File = str_replace(';','#',$File);
$Handle = fopen($File, 'w');
$Data = $section;
fwrite($Handle, $Data);
print "Data Written"; die;
When I open the text file it shows me special characters and when I convert csv to text it shows me the right result. Please provide any helpful links.
You cannot read the Excel file that way. Excel file is binary file that follows the XLS format while file_get_contents is for pure text file. You need a library (like https://github.com/PHPOffice/PHPExcel) to read the content then write to text.

Fopen problems in php

In PHP im creating a tool to open txt file with an integer in it, increment the number, save the number to a variable and then save and close the file. this is the code i have for it and it doesnt seem to work when i have it on my test server. Can anyone clue me in as to why this isnt working properly?
//opens pclnumber.txt to $handle, saves number to $number, Increments number in text file, saves and closes file
$handle = fopen("pclnumber.txt", "w+");
$number = fread($handle);
fwrite($handle, $number+1);
fclose($handle);
over all you must set reading permission on your file, and than you can use the follow code:
$filename = "pclnumber.txt";
//read file content
$handle = fopen($filename, "r");
$number = fread($handle, sizeof($filename));
fclose($handle);
//update file content
$handleWrite = fopen($filename, "w+");
fwrite($handleWrite, $number+1);
fclose($handleWrite);
Bye,
Marco

Extracting text between values in txt file using php

Im trying to extract the values between eng_tid
and eng_data for http://fdguirhgeruih.x10.mx/html.txt and I keep getting T string errors.
why do I keep getting errors
<? php
//First, open the file. Change your filename
$file = "http://fdguirhgeruih.x10.mx/html.txt";
$word1='tid';
$word2='data';
$handle = fopen($file, "r");
$contents = fread($handle, filesize($file));
fclose($handle);
$between=substr($contents, strpos($contents, $word1), strpos($contents, $word2) - strpos($contents, $word1));
echo $between;
?>
UPDATE after seeing error messages...
Instead of fread() and attempting to use the size in bytes of your target file, you may simply use file_get_contents() to retrieve the remote file. Your error is because PHP wants to read the filesize of the file as though it is local, but it is a remote file over HTTP. filesize() reports 0 and an error. Instead do
// Don't do this...
//$handle = fopen($file, "r");
//$contents = fread($handle, filesize($file));
//fclose($handle);
// Instead do this...
$contents = file_get_contents($file);

php hexdecimal conversion of png file

I am trying to get the image header from a png file. as the binary content show as neeble how can i show it as hexadecimal? i tried to base_convert() but it is not returning the desired output as i am getting the poutput in hexadecimel editor. any help will be appreciated.I am trying to do it with php
Try this for size:
$filename = "C:\\wamp\\www\\projects\\cog.png";
$handle = fopen($filename, "rb");
$binContents = fread($handle, filesize($filename));
fclose($handle);
$hexContents = bin2hex($binContents);
echo $hexContents;

Write to file in PHP?

Well actually, I already know how to write a file, but how do I write data to a file where the newest data added is at the top? I know how to do this, but the newest information is at the bottom. By the way, just to clarify, I do need all of the data to be displayed, not just the newest one.
Do you mean append or prepend? This will append:
$fp = fopen('data.txt', 'w');
fwrite($fp, '1');
fwrite($fp, '23');
fclose($fp);
This will prepend:
$handle = fopen('file.txt', "r+");
$read = fread($handle, filesize($file));
$data = $newStuff . $read;
if (!fwrite($handle, $data)) {
echo 'fail';
} else {
echo 'success';
}
If you want to append some text to the file content it's better to use another function:
file_put_contents('data.txt', '123', FILE_APPEND)

Categories