Re: Using PSpell to check an HTML document
| From: | Marek Kilimajer | Date: | Tue, 29 Apr 2003 12:49:51 +0000 |
| Subject: | Re: Using PSpell to check an HTML document | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145635@lists.php.net to get a copy of this message | ||
I just wanted to try it out, but found it was not working on my system, something must be messed up (Wrong value for parameter 4 in call to preg_match_all()).
But anyways, it should give you the strings between <something> and <something> together with the offset at which they occured. You should loop the $out array (I don't know what it contains, so find out yourself) exploding it upon white spaces:
preg_match_all ("|\s+|U", $out[index1][index2], $words, PREG_OFFSET_CAPTURE);
Now you have the words, do whatever logic you want, and replace it at offset given by adding the first offset (from the first search) to the second (each for the particular match).
Hope you got it, but I cannot help you more, as PREG_OFFSET_CAPTURE does not work on my system (I have to find out why).
Lewis Johnston wrote:
OK...that's a little beyond my understanding I'm afraid. What is that supposed to do? And, how would you use that to replace the mispelled words with the correct ones? Lewis At 02:16 PM 4/29/2003 +0200, you wrote:Trypreg_match_all ("|<[^>]+>(.*)</[^>]+>|U", "<b>example: </b><div align=left>this is a test</div>", $out, PREG_OFFSET_CAPTURE);taken from the manual so might not be 100% bullet proof, do print_r($out) to find out what it returns. Lewis Johnston wrote:I know how to use strip_tags()...and I can see how it would be part of the solution, but the main problem is fining a way to replace the corrected words into the original HTML document. Any advise on that end? At 02:04 PM 4/29/2003 +0200, you wrote:check strip_tags() and preg_split() OrangeHairedBoy wrote:I would like to be able to spell-check an HTML document...and I'm thinking about using PSpell. But, I need to extract a list of words from the document (while stripping out HTML tags), and put them into an array, which I would then use on the PSpell program. Does anyone know how to do that? If I wasn't too clear, here's an example: <head> <title>My Page</title> </head> <body> <p>Paragraph 1</p> <p>Paragraph 2</p> </body> </html> would be turned into an array I would use like: echo $words[0]; /* prints "My" */ echo $words[1]; /* prints "Page" */ echo $words[2]; /* prints "Paragraph" */ echo $words[3]; /* prints "1" */ echo $words[4]; /* prints "Paragraph" */ echo $words[5]; /* prints "2" */ Thanks! Lewis