从字符串中提取文本到“:”冒号,如果存在?

My app stores strings in this way:

Yanone+Kaffeesatz:700
PT+Sans+Narrow
PT+Sans+Narrow:regular,bold
...etc

I need to transform each of these strings so that the end result is everything to the left of the colon (if there is one).

Any help much appreciated.

Use strtok()

$sub = strtok($string, ':');
$s = preg_replace('/:.*/', '', $s);

ideone

list($key, $value) = explode(':', $inputLine, 2);

In case you really don't need the value, you can just omit it.

This should do it

$string = "whatever you want your string to be";

$tok_string = strtok($string, ':');