User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 423,804 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,735 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 507 | Replies: 4
Reply
Join Date: Mar 2008
Posts: 83
Reputation: queenc is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 3
queenc's Avatar
queenc queenc is offline Offline
Junior Poster in Training

first string in a file

  #1  
Apr 24th, 2008
hi i have written a code for convertingo uploaded a .doc and view it as html........
i am not able to view thw first line,all the bold string are looking like ordinary string
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2008
Posts: 83
Reputation: queenc is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 3
queenc's Avatar
queenc queenc is offline Offline
Junior Poster in Training

Re: first string in a file

  #2  
Apr 24th, 2008
code
   $fileHandle = fopen($userDoc, "r");
    $line = @fread($fileHandle, filesize($userDoc));   
   $lines = explode(chr(0x0D),$line);
    $outtext = "";
   foreach($lines as $line_num => $thisline)
      {
 
if ($line_num >=0 && $line_num <=150 ) {
        $pos = strpos($thisline, chr(0x00));
        if (($pos !== FALSE)||(strlen($thisline)==0))
 {
 } 
else

{
 $outtext = $thisline;
    $outtext = preg_replace("/[^a-zA-Z0-9\s\,\.\-\n\r\t@\/\_\(\)]/"," ",$outtext);
 echo  "<table>";
echo  "<tr><td>" .htmlspecialchars($outtext). "</td></tr>";
 echo  "</table>";
}
}
}
Reply With Quote  
Join Date: Sep 2005
Posts: 689
Reputation: digital-ether has a spectacular aura about digital-ether has a spectacular aura about 
Rep Power: 6
Solved Threads: 41
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Re: first string in a file

  #3  
Apr 24th, 2008
could you post some example output?

as it is you're putting everything in htmlspecialchars($outtext) so it won't be formatted.
To convert the formatting to HTML formatting, you'll have to know the doc formatting syntax (it's probably version dependent). Then convert each doc formatting into the equivalent HTML formatting.

A program that handles .doc files pretty well and is open source is OpenOffice. Its Java I believe. You can browse the source code to see just how they do it.. though it may be abstracted a bit so any references you can find on the .doc formatting would probably get you there faster.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Join Date: Mar 2008
Posts: 83
Reputation: queenc is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 3
queenc's Avatar
queenc queenc is offline Offline
Junior Poster in Training

Re: first string in a file

  #4  
Apr 25th, 2008
hi
i have attached the code i the first file and he output in the second file.In the output file..
the expected output is 139 lines only but it displaying junk values
Attached Files
File Type: txt wordtohtml.txt (1.2 KB, 1 views)
File Type: txt output.txt (13.9 KB, 1 views)
Reply With Quote  
Join Date: May 2008
Posts: 1
Reputation: Fred_Castro is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Fred_Castro Fred_Castro is offline Offline
Newbie Poster

Re: first string in a file

  #5  
May 11th, 2008
Hi,
I was trying to read MS Word documents but without good results, cause those strange characters.

I then started looking for something on google and I found your code above.
After some changes, I managed to read the first line and remove the junk at the end of the document.

It worked with 97 - 2003 .doc files

Thanks a lot, without your code I wouldn´t have done it.

Here´s the code

<?
	// Read the file and split it into lines
	$pathToFile = "path\\to\\file.doc";
	$lines = explode(chr(0x0D), file_get_contents($pathToFile, "r"));
	
	$outText = "";
	
	// Take care of the first line and removes it from the lines array
	$firstLine = explode(chr(0x00), array_shift($lines));
	$outText .= "<p>".$firstLine[sizeof($firstLine)-1]."</p>\n";
	
	// Read each line found in the doc
	foreach ($lines as $line){
		//Stop if find any weird thing
		$pos = substr_count($line, chr(0x00));
		if (($pos != false)) break;
		
		//No weird thing, add to outText, removing some strange characters
		$line = preg_replace("/[^\w ]/", "", $line);
		$outText .= "<p>".$line."</p>\n";	
	}
	
	// Print the results
	echo ($outText);
?>

I created an account here just to thank you!
All I can tell you about the bold and formatting stuff is that all the information is writen at the end of the file and you need to read the .doc file especification if you want to learn about it.

Thanks, and if I find something to make this code better, I´ll tell you.

(sorry for my english)
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 2:48 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC