Would anyone perhaps know how to get the value of a specific element in an HTML document with PHP? What I’m doing right now is using file_get_contents to pull up the HTML code from another website, and on that website there is a textarea:
<textarea id="body" name="body" rows="12" cols="75" tabindex="1">Hello World!</textarea>
What I want to do is have my script do the file_get_contents and just pull out the “Hello World!” from the textarea. Is that possible? Sorry for bugging you guys, again, you give such helpful advice :].
Don’t be sorry for bugging us, this is a good question I’m happy to answer. You can use PHP Simple HTML DOM Parser to get what you need:
If you want to use
file_get_contents(), you can do it like this:Although I don’t see any need for the
file_get_contents()as you can use theoutertextmethod to get the original, full HTML out if you need it somewhere:Just for the kicks, you can do this also with an one-liner regular expression:
I’d strongly advise against this though as you are a lot more vulnerable to code changes which might break this regular expression.