Reputation: 9
I have the following string
"DJ Antoine, Conor Maynard - Dancing In The Headlights - teledysk, tekst piosenki"
and I would like to get only:
"DJ Antoine, Conor Maynard - Dancing In The Headlights"
I use regex but it not working:
^([^\;]+)$ - teledysk, tekst piosenki
Upvotes: 0
Views: 66
Reputation: 21489
Use preg_replace()
to remove additional part of string. The regex select additional part and replace it with empty.
$str = preg_replace("/-[\w\s,]+$/", "", $str);
See result in demo
Upvotes: 0
Reputation: 4579
Here is my two cents :
php > $s = "DJ Antoine, Conor Maynard - Dancing In The Headlights - teledysk, tekst piosenki";
php > $new_s = explode('-', $s, -1);
php > echo implode('-', $new_s);
DJ Antoine, Conor Maynard - Dancing In The Headlights
Upvotes: 1