Old 06-04-2004, 16:53   #1 (permalink)
dcd
Senior Member
 
dcd's Avatar
 
Join Date: Feb 2003
Location: Canterbury
Posts: 103
rtf using php...

Hi

I'm using a rtf document to update a news section of a website by the means of php.

The code:
<? include("whatson.rtf"); ?>

This works, my problem is in formatting it - I can use the style sheets on it, that all works but it doesn't keep the original formatting of the rtf document - is there a way of doing this?

If you want the example - www.designmedication.co.uk/homepage.php
The rtf: www.designmedication.co.uk/whatson.rtf

Any help would be much appreciated!

Matt
  Reply With Quote
Old 06-04-2004, 18:48   #2 (permalink)
Bill Posters
trouble free and loverlee
 
Join Date: Mar 2003
Location: YooKay
Posts: 2,933
I"m working with something like that on a current job by way of making it simpler for clients to provide important content.

You might find it simpler to switch to plain text (.txt) as it's easier to transfer, store and process.

I've used the following set of php instructions to reformat the text as markup

PHP Code:
$filename "path/to/textfile.txt";
$file fopen($filename"r");
$text fread($filefilesize($filename));
fclose($file);

$text ereg_replace("\r","",$text);
$text ereg_replace("\n","<br />",$text);
$text ereg_replace("<br /><br />","</p>\n<p>",$text);

echo(
$text); 

That's just a simplified section of a larger function I've put together that writes and format dynamic modular sections of a gallery site and imports the artists' bios in the scheme.
It does a good job of translating the untagged, loosely formatted text of the txt file into properly tagged, well-presented on-screen text.

With a little tweaking of the \n (php new line) and \t (php new tab) you can set things up to produce seamless, tab-perfect markup that holds up well in view source.

It's great to see it when it works.
I'm still new to php and I only sorted the large artist handler function y/day, so I'm still in that 'isn't php great' and feeling just a little proud of myself.

In the words of the great Hannibal Smith - I love it when a plan comes together.
  Reply With Quote
Old 07-04-2004, 04:58   #3 (permalink)
dcd
Senior Member
 
dcd's Avatar
 
Join Date: Feb 2003
Location: Canterbury
Posts: 103
Thanks

I'll have a play round with that - I'm even newer to php, started y'day!! So yeah, php is GREAT!!!

Matt
__________________
Living in the Slow Lane
  Reply With Quote
Old 07-04-2004, 05:11   #4 (permalink)
dcd
Senior Member
 
dcd's Avatar
 
Join Date: Feb 2003
Location: Canterbury
Posts: 103
You're a genius mate !!

It works, my only problem now is inserting bold and italics into it. Is there any way of doing that?

Matt
__________________
Living in the Slow Lane
  Reply With Quote
Old 07-04-2004, 05:31   #5 (permalink)
Bill Posters
trouble free and loverlee
 
Join Date: Mar 2003
Location: YooKay
Posts: 2,933
If it's certain defined words you wish to emphasise then you can do it using the same method as above.

e.g. if you wanted to turn any reference to your name into a simple, clickable email link or simply style it…
PHP Code:
$text ereg_replace("Your Name","<a href=\"mailto:yourname@yourdomain.com\">Your Name</a>",$text); 
or
PHP Code:
$text ereg_replace("Your Name","<strong>Your Name</strong>",$text); 

If you want to allow users/clients to input their own data and have styling applied as and when they want then that's when things get a tad more complex - and I bow out, having hit my ceiling.


You might want to check out the PHP sections of Hotscripts.com to see what's available.
You may well find precisely the facility you're after.
http://www.hotscripts.com/PHP/Tips_and_Tutorials/

Last edited by Bill Posters : 07-04-2004 at 05:41.
  Reply With Quote
Old 07-04-2004, 06:20   #6 (permalink)
smallbeer
I Ain't Losing Any Sleep™
 
Join Date: Apr 2003
Posts: 5,200
Bold
Code:
$text = str_replace(array('[b]','[b]'),'<strong>',$text); $text = str_replace(array('[eb]','[EB]'),'</strong>',$text);
Italic
Code:
$text = str_replace(array('[i]','[i]'),'<em>',$text); $text = str_replace(array('[ei]','[EI]'),'</em>',$text);
Links
Code:
$text = eregi_replace('\[L]([-_./a-zA-Z0-9!&%#?+,\'=:~]+)\[/L]','<a href="http://\\1">\\1</a>', $text); $text = eregi_replace( '\[L=([-_./a-zA-Z0-9 !&%#?+,\'=:~]+)]'.'([-_./a-zA-Z0-9!()&%#?+ ,\'=:~]+)\[EL]', '<a href="\\1">\\2</a>', $text);
__________________
That's fuckin' ingenious, if I understand it correctly. It's a Swiss fuckin' watch.
  Reply With Quote
Old 07-04-2004, 06:22   #7 (permalink)
Bill Posters
trouble free and loverlee
 
Join Date: Mar 2003
Location: YooKay
Posts: 2,933
Can you explain that in layman's terms, sb?

tia
  Reply With Quote
Old 07-04-2004, 06:31   #8 (permalink)
Bill Posters
trouble free and loverlee
 
Join Date: Mar 2003
Location: YooKay
Posts: 2,933
Aah, seems you've edited it.
now it makes sense.


Of course, there's that option, but I thought the idea might be to shield users from learning even the most basic hand-code.

Also: if you're simply replacing ad-hoc tags with meaningful ones, why not simply get users to add their own <strong>…</strong> and <em>…</em> tags in the first place?
  Reply With Quote
Old 07-04-2004, 06:39   #9 (permalink)
smallbeer
I Ain't Losing Any Sleep™
 
Join Date: Apr 2003
Posts: 5,200
Yeah, edited because the board thought I was entering it's own code at first.

Quote:
Originally Posted by Bill Posters
Also: if you're simply replacing ad-hoc tags with meaningful ones, why not simply get users to add their own <strong>…</strong> and <em>…</em> tags in the first place?

Because you don't really want a user to be able to enter their own (x)html and invalidate yours or worse, fuck up your layout.

Use htmlspecialcharacters() to neutralise any xhtml that the user enters but give them some "ad-hoc" tags to preform some basic formating.
__________________
That's fuckin' ingenious, if I understand it correctly. It's a Swiss fuckin' watch.
  Reply With Quote
Old 07-04-2004, 06:45   #10 (permalink)
Bill Posters
trouble free and loverlee
 
Join Date: Mar 2003
Location: YooKay
Posts: 2,933
k, now i geddit. ta
  Reply With Quote
Old 29-06-2004, 20:45   #11 (permalink)
strawbleu
Senior Member
 
strawbleu's Avatar
 
Join Date: May 2004
Location: Leeds, UK
Posts: 273
Send a message via MSN to strawbleu
I've a similar situation, a client wants to be able to import RTF documents into his intranet, and the nice app will break the document into data fields based on the bulleted lists within the rtf (each item becomes a seperate record within the db).

This is for ASP - but are there any simple references on the subject?
__________________
Jon Eland :: StrawBleu
Web evangelist, photographic imagemaker and all-round good egg.
  Reply With Quote
Old 30-06-2004, 04:12   #12 (permalink)
stickmus
hmmm...
 
stickmus's Avatar
 
Join Date: Jan 2004
Location: Yorkuk
Posts: 2,127
  Reply With Quote
Old 30-06-2004, 05:12   #13 (permalink)
cam
vague™
 
cam's Avatar
 
Join Date: Mar 2004
Location: Glasgow
Posts: 5,512
Quote:
Originally Posted by stickmus

Yeah, a google search for "rtf to html" php.

That'll help for a project to be done in asp.

Commercial solution: http://www.easybyte.com/products/rtf2html.html

couldn't find any decent tutorials but i'm sure there'll be some somewhere..
__________________
  Reply With Quote
Old 30-06-2004, 05:20   #14 (permalink)
strawbleu
Senior Member
 
strawbleu's Avatar
 
Join Date: May 2004
Location: Leeds, UK
Posts: 273
Send a message via MSN to strawbleu
now that's annoying - I'm sure I did those searches last night.

>> Feels v stupid / befuddled <<

Thanks, guys!
__________________
Jon Eland :: StrawBleu
Web evangelist, photographic imagemaker and all-round good egg.
  Reply With Quote
Old 30-06-2004, 07:45   #15 (permalink)
andymoo
Crazy Frog
 
Join Date: Jun 2004
Location: Liverpool
Posts: 42
Send a message via ICQ to andymoo Send a message via Yahoo to andymoo
$data = "blah
Blah
blah";

nl2br($data);

echo "$data";

would echo:

blah<br>blah<br>blah

easier than replacing as this fucntion converts newlines to br's

hth
  Reply With Quote
Old 30-06-2004, 07:55   #16 (permalink)
Bill Posters
trouble free and loverlee
 
Join Date: Mar 2003
Location: YooKay
Posts: 2,933
I tried that and while it is a good, quick way of achieving markup from text, but it didn't produce markup that satisfied my preference for good, clean, well-tabbed end markup.

-

Fwiw, in PHP 4.05+ nl2br() produces xhtml-compliant <br /> tags.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8