Jump to content

Replace "." in the text


sandy1028

Recommended Posts

In the  text,

 

It will eventually go away.Once the carriers merge, the combined airline, will operate as Southwest. It has its logo and colors. 2.3 AirTran brand will no longer be used. 

 

In the above text, how to replace "." with ". "  and not in 2.3.

 

how to add space after "." only if it has alphabets and not to replace after numeric characters.

Link to comment
https://forums.phpfreaks.com/topic/250274-replace-in-the-text/
Share on other sites

<?php

$str = 'It will eventually go away.Once the carriers merge, the combined airline, will operate as Southwest. It has its logo and colors. 2.3 AirTran brand will no longer be used. ';

$patt = '~(\.)([^\d\s])~'; //select a period that is NOT followed by a numerical digit or a space (capturing the space in the 1st group, and the alpha character in the second group).

$str = preg_replace($patt,'$1 $2',$str); //replace the pattern with the 1st capture and the 2nd capture separated by a space.

echo $str;

?>

Link to comment
https://forums.phpfreaks.com/topic/250274-replace-in-the-text/#findComment-1284375
Share on other sites

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.