Re: preserving tabs

From: Date: Tue, 04 Jul 2000 14:29:24 +0000
Subject: Re: preserving tabs
Groups: php.general 
Request: Send a blank email to php-general+get-4752@lists.php.net to get a copy of this message
You have to distinguish between what's in the HTML source and what the browser does with it. Your problem is comparable to the "newline" topic we had over and over on this list in the last few weeks. The \t character in the HTML source will be interpreted as a blank. The tabs are present, but they don't mean anything to the browser. So if you want to have a table-like presentation of your data, you have to replace every \t by a new columns "</td><td>" and every newline \n by a new table row "</td></tr><tr><td>". After all you have to prepend a "<table><tr><td>" and append a "</td></tr></table>" to your data. There is a php function that does it for you: From the manual http://www.php.net/manual/function.ereg-replace.php : string ereg_replace (string pattern, string replacement, string string) This function scans string for matches to pattern, then replaces the matched text with replacement. try: <?php $output="<table><tr><td>"; $your_text=ereg_replace("\t","</td><td>",$your_text); $your_text=ereg_replace("\n","</td></tr><tr><td>",$your_text); $output="<table><tr><td>$your_text</td></tr></table>"; ?> But this code does not check, if the HTML code is well-formed (missing end tags a.s.o). May be there's a better way?! There are several functions that work in this direction but won't probably meet your requirements: htmlspecialchars(), htmlentities(), nl2br(). Refer to the manual. HTH --Steff webmaster@posh.ch www.posh.ch |-------------> |(Embedded | |image moved | |to file: | |pic01106.pcx)| | | |-------------> >------------------------------------------------------------------------| |david.tansley@acelondon.co.uk | |04.07.2000 15:55 | >------------------------------------------------------------------------| To: php-general@lists.php.net cc: (bcc: Stephan Schoell/CHHOS/ABB) Subject: [PHP] preserving tabs Security Level:? Internal when i insert a text field into mysql, it sometimes contains tabs, but when i view the record on a html page the tabs have gone. doing a select on the table from the mysql command line, show the tabs present. Using \" $mytext\" when displaying the txt field does not fix it DT ________________________________________________________________________ CONFIDENTIALITY This e-mail and any attachments are confidential and may also be privileged. If you are not the intended recipient(s) please note that any distribution, copying or use of this communication or the information in it is strictly prohibited.If you are not the named recipient(s), please notify the sender immediately and do not disclose the contents to another person, use it for any purpose, or store or copy the information in any medium. > ************ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#4752) next »