Jump to content

Smart Text


The Little Guy

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.