string splitting (preg_split)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cronus
Forum Newbie
Posts: 2
Joined: Sat Dec 20, 2008 10:17 am

string splitting (preg_split)

Post 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?
rich86
Forum Newbie
Posts: 15
Joined: Sun Jun 11, 2006 7:30 pm

Re: string splitting (preg_split)

Post 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.
Post Reply