简体   繁体   中英

php get value from textarea

how can i get value from field textarea. i want to detail- i need to parse html page and get value from field textarea not call something like $_POST["textarea"]

Option 1

Best way for parsing like this is to use DOM, http://www.php.net/manual/en/book.dom.php After you load your page into the DOM, you can use getElementById('textarea_id') , php docs are here . If your text area has ID or getElementsByTagName('textarea') , but in this case you will get NodeList. So it will look something like this:

// dom
$nodes = $dom->getElementsByTagName('textarea');
$node1 = $nodes->item(0);


Option 2

Another option is to get the page as string and use regular expression to match your textbox and get info out of it. I found this class in google, it is HTML Form Parser - http://www.alexandruion.com/html-form-parser

This didn't work for me:

// dom
$nodes = $dom->getElementsByTagName('textarea');
$node1 = $nodes->item(0);

I used $node1 = $nodes->item(0)->nodeValue; since the class DOMElement inherit the DOMNode properties as you can see here .

这要简单得多,但这应该可以工作(假设稍后再打印$ display)

$display .= "<textarea name='notes' rows='3' cols='30'>".$notes."</textarea><br />";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM