Jump to content

Removing extra periods after sentance


Go to solution Solved by Psycho,

Recommended Posts

Hello, I have a very simple problem I am sure for some. I have a file I am parsing using SimpleXML. The data includes extra periods after the sentences like this. 

 

 

 

...FIRE WEATHER WATCH REMAINS IN EFFECT FROM WEDNESDAY AFTERNOON THROUGH WEDNESDAY EVENING FOR STRONG WINDS AND LOW RELATIVE HUMIDITY FOR THE SOUTHERN AND EASTERN TEXAS PANHANDLE AND THE EASTERN HALF OF THE OKLAHOMA PANHANDLE... * AFFECTED AREA...IN OKLAHOMA...TEXAS AND BEAVER. IN TEXAS... HANSFORD...OCHILTREE...LIPSCOMB...HUTCHINSON...ROBERTS...

 

This is causing me problems with doing preg_replace and strtoupper to capitalize the first letter of the sentence I think due to the extra periods after sentences since it is looking for only one period and not three. My question is how could I go about stripping two of the periods from the three? 

 

-Thanks

Link to comment
https://forums.phpfreaks.com/topic/287625-removing-extra-periods-after-sentance/
Share on other sites

I got it sorted like this. 

// Replaces all triple periods with single periods
        $summary = str_replace('...', '.', $summary);
  //now capitalize every letter after a . ? and ! followed by space
        $Summary = preg_replace_callback('/([.!?])\s*(\w)/', function ($matches) {
            return strtoupper($matches[1] . ' ' . $matches[2]);
            }, ucfirst(strtolower($summary)));

But is there a way to remove periods from certain areas instead of all?

At the beginning. The data I am parsing adds ... at the beginning of the as well as other areas. The other areas are fine as I was able to remove the extra periods but, at the beginning of the paragraph there is a period that I would like to remove if posible but not certain how to go about that. 

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.