<html>
<head><title>Example page</title></head>
<body>
<textarea name="description">This is some text</textarea>
<input type='text' name='bla' value='a textinput' />
<textarea name="interests">What i like to do</textarea>
</body>
</html>
The above html code is the value of a variable. I want to grab all the textareas and replace them by something. What would be the way to get following array from the string:
1: <textarea name="description">This is some text</textarea>
2: <textarea name="interests">What i like to do</textarea>
DOMDocument->loadHTML()to load the HTML as a DOM tree,textareaelements (and their text nodes)Cf. Robust, Mature HTML Parser for PHP
In essence: avoid regular expressions for this kind of tasks. If you insist (and the HTML is guaranteed to be as simple as indicated), try:
(demo)