Jump to content

Character match, text change and space removal HELP!.


jamesxg1

Recommended Posts

Hiya peeps,

 

This is something very complicated and I'm in need of some help I need to do the following.

 

EXAMPLE TEXT = 'hiya, Bye for now';

 

How do I do the following?

 

1) Add a ' . ' dot at the end, remove any space from the end.

2) recognise the comma and change 'Bye for now' into 'bye for now'.

 

Many thanks

 

James.

This should get you on your way:

 

$string = "hiya, Bye for now";
$string = ucfirst(strtolower($string)); // Make it all lowercase then format the first word uppercase.
$string = trim($string); // Remove whitespace.
if(substr($string, -1) !== ".") $string .= "."; // Add a full stop if it doesn't already have one.
echo $string; // Should produce: Hiya, bye for now.

Thats stunning thanks guys, I've got another lil issue so to save opening another thread, I will post here.

 


                        $input= 'hiya, how are you?';
                        $match = array('how are you');
		$output = array();

		foreach($match as $sentence_split):
			$sentence_split_slash = '/' . $sentence_split . '/';
			if(preg_match($sentence_split_slash, $input)):
				$output[] = $sentence_split;
			else:
				$this->conversate_word($sentence_split);
			endif;
		endforeach;

 

how do I make it so that the 'hiya' is actually sent to $this->conversate_word();

 

 

Many thanks

 

James.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.