How can i strip out the code after the "-" (including the -) in this title using php?
Buying a Home - Conveyancing Solicitors Dorset, Devon & Cornwall - LCS Legal Services
How can i strip out the code after the "-" (including the -) in this title using php?
Buying a Home - Conveyancing Solicitors Dorset, Devon & Cornwall - LCS Legal Services
$str = 'Buying a Home - Conveyancing Solicitors Dorset, Devon & Cornwall - LCS Legal Services
';
// find first occurrence of '-'
$pos = strpos($str, '-');
// if '-' found, take the substring from the beginning to the position found
$str = ($pos !== false) ? substr($str, 0, $pos) : $str;
use explode on "-" and get first element.
$str = "Buying a Home - Conveyancing Solicitors Dorset, Devon & Cornwall - LCS Legal Services";
$s = explode("-",$str);
print $s[0];