You are here: Re: How to split string around textarea tags? « PHP Programming Language « IT news, forums, messages
Re: How to split string around textarea tags?

Posted by Rik Wasmus on 01/04/08 22:26

On Fri, 04 Jan 2008 23:05:56 +0100, <nubster21@yahoo.com> 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?

> <div>Hello this is my content <textarea>foo</textarea> and this is
> also
> content <b>some bold text</b> <textarea>bar and so forth...</textarea>=

> here my final content.</div>
>
> The output should be:
>
> Array(
> 0 =3D> <div>Hello this is my content
> 1 =3D> <textarea>foo</textarea>
> 2 =3D> and this is also content <b>some bold text</b>
> 3 =3D> <textarea>bar and so forth...</textarea>
> 4 =3D> here my final content.</div>
> );
>
> 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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация