Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 414
  • Last Modified:

PHP form to parse html

My question is if there is a relatively easy way for my site to preserve xcel, word and other formatted documents, including html formatting. Right now my form removes all formatting and I was thinking perhaps that somebody has a function I could use or something...
1 Solution
rae_raeAuthor Commented:
I've seen a program that somehow loads a blank html document into the form textarea...
My form is laid out like this:
            // For news forms---------------------------------------------------------------------
            case 'form_news':
            echo '<table border="0"><tr><td><align="left">';
            echo '<form action="processor.php?sender=ins_news" method="post">';
            echo '<fieldset>';
            echo '<legend>Insert New News Section</legend>';
            echo 'News Title:';
            echo '<br><input type="text" name="content_name"><br>';
            echo 'News Body:';
            echo '<br><textarea rows="8" cols="30" name="content_body"></textarea><br>';
            echo 'Positon [100 shows before 200]:<br>';
            echo '<input type="text" size="3" name="content_position">';
            echo '<input type="Submit" value="Submit">';
            echo '<input type="Reset">';
            echo '</form>';
            echo '</fieldset>';
            echo '</td></tr></table>';
            $displ_query  = "SELECT content_name, content_position FROM News_Content ORDER BY content_position";
            $result       = mysql_query($displ_query);
            echo '<font size="2"><b>News Title and Section Position Already entered:</b></font><br>';
            while($row = mysql_fetch_array($result, MYSQL_ASSOC))
                        echo "<font size='2'> {$row['content_name']} {$row['content_position']} </font><br>";
            echo '<a href="processor.php?sender=cpanel">Back to Admin Panel</a>';
            // ----------------------------------------------------------------------------------
of couse, make header actually contain the css and regular <html><body> and make_footer contains </body></html>
it is NOT POSSIBLE to maintain any external formatting inside a standard <textarea> element. This element could be styled, but after this, the style is uniform for the whole <textarea> element. it is POSSIBLE to create a special DHTML "textarea" to achieve this goal. Some online HTML editors use this strategy. You can use AJAX technology to achieve your goal, too (but this is a little bit more complicated).
(Or an applet)
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

I'm not sure I fully understand you're question, but maybe it will become clearer as I try to answer. I have to assume that you have some web form that allows users to input data, or possibly upload files, and then it parses that data and stores it somewhere. IF you allow them to upload files (e.g. Word documents in the .doc format or Excel documents in the .xls format), while nothing is impossible, it's practically impossible to keep any of the proprietary formatting that DOC and XLS use. If you've ever looked at one of those files using a plain-text editor like Notepad, you'll quickly see that the true formatting used would be an absolute nightmare to deal with.

However, if you're not uploading files and you're merely letting users input things on the web (for instance, in a textarea element as some people have mentioned), then the clear answer is to use a WYSIWYG input form. There are many of these freely available on the internet, I prefer this one myself:

These use JavaScript to let users input "rich text," so that "what you see is what you get." If you have created a document in Word, you may literally copy/paste it into one of these WYSIWYG editors and will look exactly the same. Likewise with Excel. The JavaScript changes the Word or Excel format into HTML, and then if you submit that form to a PHP script, what you get is a bunch of text with HTML formatting. If you wanted ONLY the text part and none of the formatting, you could use PHP's built-in function strip_tags() to remove the HTML. Otherwise, the data would be saved along with any formatting, so that when you output it in the web browser, it would look exactly like it did in Word in Excel (more or less).
rae_raeAuthor Commented:
How can I check for the existence of a string of characters within a php variable? Thanks!
There are many functions to do this sort of thing. Since there are myriad ways of "checking for existence," I'll name a few and briefly describe them.

if ( isset($var) )
    // If $var has been assigned to literally anything at all

if ( strlen($var) )
    // If $var has a "string length" greater than zero, this is true
    // This one is a stronger test than isset(), but please note
    // that integers have "string length" values as well. For instance,
    // strlen(29) == 2, because it would convert 29 to "29"

if ( !empty($var) )
    // empty() checks to see whether the variable is empty or not. (duh)
    // This conditional is the negation of that.

if ( is_string($var) )
    // For obvious reasons, this one is probably the most reliable for
    // checking whether $var is a string or not. This one's even stronger
    // than strlen(), because it would return FALSE if an integer was entered.
    // However, is_string("") returns TRUE (for the empty string). It does return
    // false for this, though: is_string(NULL)

I frequently use "if ( strlen($var) )" to test for things, because it's nice and clean. It only requires that the input has length greater than zero. I'd recommend to use that one, anyway. If you really, really, really want to ensure that your input is not strictly a number, then use is_string, but otherwise strlen() is fine.

Browse on over to www.php.net. They have a search engine on the top right that lets you look through every single function that is defined in PHP with elaborate explanations for each and a list of similar functions on the left side. It's really quite helpful.
rae_raeAuthor Commented:
Thanks Soapergem for your invaluable help and willingness to explain things! I'll definately give all this a wirl and see what I can come up with.
Maybe you could give it a 'whirl' as well. ;)

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now