The Little Guy Posted December 18, 2009 Share Posted December 18, 2009 I am using pspell, and when a user enters some text and submits it, I check the words, but I need to remove the punctuation first so I have this: $str = preg_replace('/\W[ ]/', ' ', $_GET['q']); I then create an array from the spaces and check each word like so: $words = explode(" ", $str); $pspell_link = pspell_new("en"); $errors = 0; $errorStr = ""; foreach($words as $word){ if(!pspell_check($pspell_link, $word)){ $suggestions = pspell_suggest($pspell_link, $word); $errorStr .= "<b>".$suggestions[0]."</b> "; $errors++; }else{ $errorStr .= $word." "; } } So, now I would like to display the string, with the errors, in bold (like in the code), but how do I put the punctuation back? Link to comment https://forums.phpfreaks.com/topic/185563-remove-then-add-punctuation-from-string/ Share on other sites More sharing options...
teynon Posted December 18, 2009 Share Posted December 18, 2009 Put $str = preg_replace('/\W[ ]/', ' ', $_GET['q']); inside of the foreach and execute it individually on each word. But use it like so: $checkWord=preg_replace('/\W[ /', ' ', $word); Then do your spell check on "$checkWord". Now, if it needs modified, modify the actual array value. -Change your foreach to foreach($words as $key=>$word){ and replace the word with: $words[$key]="<b>{$word}</b>"; Then at the end, use "implode" to put your string back together. Link to comment https://forums.phpfreaks.com/topic/185563-remove-then-add-punctuation-from-string/#findComment-979716 Share on other sites More sharing options...
The Little Guy Posted December 19, 2009 Author Share Posted December 19, 2009 OK, I am confused... How do I break the string up before the foreach with that? I think I see where your going with that though... maybe... Link to comment https://forums.phpfreaks.com/topic/185563-remove-then-add-punctuation-from-string/#findComment-980398 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.