获取字符的子字符串直到第一次出现点或破折号[重复]

How do you specify that you want to return a substring containing all characters from the start of a string up to but not including the first dot or dash?

For example if the original string is:

'abcdefg.hij-k'

or if the original string is:

'abcdefg.hi-j.k.l.mn-op'

Then the same substring of:

'abcdefg'

should be returned.

The key thing here is that there may be multiple dots and dashes occurring randomly and we are only interested in the first chunk of characters.

EDIT: A dot or a dash may occur first.

</div>

You could use preg_split:

$res = preg_split('/[-.]/', $string);

The string you want is in $res[0]

Or preg_match:

preg_match('/^([^-.]+)/', $string, $matches);

The result is in $match[1]

Try using the explode function.

$final = explode(".", $originalstr);

first should be $final[0];