How to split string around textarea tags?

How to split string around textarea tags?

am 04.01.2008 23:05:56 von nubster21

I would like to split a string of HTML output into an array on
textarea tags. Example:

Hello this is my content and this is
also
content some bold text
here my final content.


The output should be:

Array(
0 =>
Hello this is my content
1 =>
2 => and this is also content some bold text
3 =>
4 => here my final content.

);

I am fairly new to PHP, so I've been browsing php.net and found some
usefull functions, including strstr, explode and str_split but don't
know how to combine these into a working function. Could anybody
please help me on my way? Your help is appreciated!

Re: How to split string around textarea tags?

am 04.01.2008 23:26:00 von luiheidsgoeroe

On Fri, 04 Jan 2008 23:05:56 +0100, wrote:

> I would like to split a string of HTML output into an array on
> textarea tags. Example:

WHat exactly do you need this textarea tags for?

>

Hello this is my content and this is
> also
> content some bold text =

> here my final content.

>
> The output should be:
>
> Array(
> 0 =3D>
Hello this is my content
> 1 =3D>
> 2 =3D> and this is also content some bold text
> 3 =3D>
> 4 =3D> here my final content.

> );
>
> I am fairly new to PHP, so I've been browsing php.net and found some
> usefull functions, including strstr, explode and str_split but don't
> know how to combine these into a working function. Could anybody
> please help me on my way? Your help is appreciated!

Some people will try to give you a regex. Don't use that, it would be =

highly unreliable, and easily broken. Try to use DOM, =

http://www.php.net/DOM

Something along these lines (untested, just an illustration):

$document =3D new DOMDocument();
$document->loadHTML($string);
textareas =3D $document->getElementsByTagname('textarea');
foreach($textareas as $text){
echo $test->textContent;
}
-- =

Rik Wasmus

Re: How to split string around textarea tags?

am 05.01.2008 00:39:03 von ivansanchez-alg

nubster21@yahoo.com wrote:

> I would like to split a string of HTML output into an array on
> textarea tags.

*If* you're dealing with well-formed XHTML, try out simplexml.

Besides that, grab a hold onto a book on compilers and parsers.


Cheers,
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.