Page 1 of 1
Attach html to text
Posted: Thu Nov 15, 2007 11:04 am
by gr3gg0r
I want to have a form that takes some text. Like a description, so it has to be able to be fairly long. I then want to write some code to add HTML formatting to the text. I want the HTML on either end of the text. So it will basically put the text into an HTML template. What are some ways I can do this? I'm fairly new to PHP and I can't seem to figure this out at all. Thanks for helping me out.
Posted: Thu Nov 15, 2007 12:47 pm
by Jonah Bron
Something like this?
Code: Select all
<form method="post" action="php_page.php">
<textarea name="desc"></textarea>
<input type="submit" value="submit" />
</form>
and php_page.php:
Code: Select all
$desc = $_POST['desc']; //get description from form
$desc = '<span style="color: #FF0000;">' . $desc . '</span>'; //add html to $desc
echo $desc; //output $desc with new formating
Posted: Thu Nov 15, 2007 3:20 pm
by gr3gg0r
That looks good to me, now what if I wanted it to create a csv file with that information in one cell?
Posted: Thu Nov 15, 2007 8:01 pm
by Jonah Bron
Yeah. I'd really help you if I knew what csv was.
Oh, I get it. It is something for saving information, right? I know how to do that with XML. Does it
have to csv?
Posted: Thu Nov 15, 2007 9:13 pm
by gr3gg0r
a csv file is a "comma seperated values" file. Like a tab delimited file, but commas. An excel spreadsheet might work too but I prefer a simpler format. I don't know too much about XML but I would be willing to learn. Tell me about that and how it works. I'm sure I could do some research on my own so perhaps just tell me how to save stuff from a php web form like the one you gave as an example to an XML type file. I basically just need a way to get the information into a spreadsheet without laboriously doing a copy and paste. In the end this should have a lot of information going through it. Thanks!
Posted: Thu Nov 15, 2007 9:39 pm
by sunilbhatia79
Are you looking at developing a script that will process HTML input put in the description by the user, or do you want to allow users to accept HTML input and then show it in another place?
Let me know so that I can help you with it.
Posted: Fri Nov 16, 2007 10:32 am
by Jonah Bron
Okay, you want to start out with an xml file like this:
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<nodes>
<node></node>
<node></node>
<node></node>
</nodes>
Each "node" tag is where the description will be.
Code: Select all
<?php
$xml = new DOMDocument(); //This starts up the DOM XML parser
$xml->load('nodes.xml'); //This loads the xml file
$nodes = $xml->getElementsByTagName('node'); //sets the var for each "node"
foreach ($nodes as $node){ //run through each "node"
echo 'Description: <p>'. $node->nodeValue .'</p>'; //output the node
}
?>
That output all values in the xml document.
This is the php to add a new "node", with the description inside it:
Code: Select all
<?php
$desc = $_POST['desc'];
$xml = new DOMDocument();
$xml->load('nodes.xml');
$root = $xml->documentElement;
$new_node = $doc->createElement('node', $desc);
$new_node = $root->appendChild($new_node);
$xml->saveXML();
?>
Posted: Fri Nov 16, 2007 6:48 pm
by gr3gg0r
sunilbhatia79 wrote:Are you looking at developing a script that will process HTML input put in the description by the user, or do you want to allow users to accept HTML input and then show it in another place?
Let me know so that I can help you with it.
I want the user to put in text, and get the text with the html added to it in some useable form.
In the end, I want the user to be able to put in a spreadsheet with any number of text field in one column and I want this to put out a spread sheet with that text with the html appended to it in one column.
Posted: Fri Nov 16, 2007 10:09 pm
by RobertGonzalez
Can you explain what you are after a little more clearly. I am having a little bit of a hard time trying to wrap my mind around you taking a text input, wrapping HTML around it then turning it into a CSV output.
Posted: Tue Nov 20, 2007 1:23 pm
by gr3gg0r
Everah wrote:Can you explain what you are after a little more clearly. I am having a little bit of a hard time trying to wrap my mind around you taking a text input, wrapping HTML around it then turning it into a CSV output.
I basically want an easy way to get a text description (and perhaps a title) formatted with an HTML template. I'm pretty sure you can do what I want with excel but I want to create this with some enhancements in mind to be made in the future. I just need to get started right now.