Jump to content

Trying to preg_replace one instance of a colon.


maxkiesler

Recommended Posts

Hi,

 

I’m having a rather tough time figuring out one simple thing. How to knock the username: off of a string for display.

 

A normal string looks like:

Steve Smith: is going out to see a fight with the guys.

 

What I’m trying to get rid of is Steve Smith: and leave everything else. I tried the following:

 

$string = Steve Smith: is going out to see a fight with the guys.;
echo preg_replace("/.*:/", "", $string);

 

This returns:

is going out to see a fight with the guys.

 

This works fine if there are no more colons in the sentence.

 

This does not work

Steve Smith: is going out to: see a fight with the guys.

Has this return:

see a fight with the guys.

 

Thanks in advance for any help.

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.