Question

I would like to remove the colon only if its the first character of a string. I have tried the following but it doesnt work. Any help would be appreciated:

//remove the colon if its the first character..

$pattern = '/^:/';
$replace = '';
$tweet = preg_replace($pattern, $replace, $tweet);
Was it helpful?

Solution

escape the colon:

$pattern = '/^\\:/';

OTHER TIPS

You can also put the colon in a set by itself, which may be easier to read:

$pattern = '/^[:]/';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top