The Little Guy Posted June 9, 2008 Share Posted June 9, 2008 I am doing an insert, and I would like to have a "Smart Text Formatting". currently what I have doesn't work: function edit_name($nedit){ $nedit = strtolower($nedit); $nedit = str_replace(array("/", "&", " "), array("", "and", " "), $nedit); $nedit = preg_replace('/^(a|an|the)\s+(.+)/i', '$2, $1', $nedit); $nedit = preg_replace('/(?<![a-z]\')\b[a-z]/e', "strtoupper('$0')", $nedit); return addslashes($nedit); } What I want it to do is the following: - uppercase a letter after a quote if it is the first letter of the word (e.g. 'N) - leave a letter lowercase after a quote if it isn't the first letter of a word (e.g. Don't) - place "a", "an", "the", at the end of the sentence, with a comma in front of it (e.g. Big One, The) - convert the ampersand to its proper text (e.g. You and Me) Link to comment https://forums.phpfreaks.com/topic/109425-smart-text/ Share on other sites More sharing options...
effigy Posted June 9, 2008 Share Posted June 9, 2008 What isn't working? I added examples: <pre> <?php $tests = array( 'The quick brown fox jumps over the lazy dog.', "'yes,' he responded; he didn't know.", 'You & Me.' ); function edit_name($nedit){ $nedit = strtolower($nedit); $nedit = str_replace(array("/", "&", " "), array("", "and", " "), $nedit); $nedit = preg_replace('/^(a|an|the)\s+(.+)/i', '$2, $1', $nedit); $nedit = preg_replace('/(?<![a-z]\')\b[a-z]/e', "strtoupper('$0')", $nedit); return addslashes($nedit); } foreach ($tests as $test) { echo edit_name($test), '<br>'; } ?> </pre> Quick Brown Fox Jumps Over The Lazy Dog., The \'Yes,\' He Responded; He Didn\'t Know. You And Me. Link to comment https://forums.phpfreaks.com/topic/109425-smart-text/#findComment-561284 Share on other sites More sharing options...
The Little Guy Posted June 9, 2008 Author Share Posted June 9, 2008 hmm... looks like I was wrong. Maybe it was something else that I for got to add to the list (haven't worked with the code for a few months). So I guess it works for now. Link to comment https://forums.phpfreaks.com/topic/109425-smart-text/#findComment-561300 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.