Page 1 of 1

string splitting (preg_split)

Posted: Sat Dec 20, 2008 10:27 am
by cronus
Hello,

I got html code, and what i want to do is to split it into: tags, words, special html entities (for example: &nbsp, &copy) and punctuation marks.

For example:

Code: Select all

<html>
<head>
Title, bla bla
</head>
<body>
some &nbsp text
</body>
</html>
 
Output:
Array = (
[0] = <html>
[1] = <head>
[2] = Title
[3] = ,
[4] = {space}
[5] = bla
....

How to do this?

Re: string splitting (preg_split)

Posted: Sat Dec 20, 2008 10:40 am
by rich86
have you tried str_word_count() info at:
http://uk.php.net/manual/en/function.str-word-count.php
it can split the string into an array of all the words.

If not then i am sure you can use preg_split to split the string at all new lines (\n) or spaces, i am not hot on regexp so someone else might be able to help with that.