I see two ways to do this, but in the end it all looks pretty similar:
replacing part
As you use str_replacein your question, and you put a zero byte in there to put an end to the line (for example, perhaps in C), what you are probably looking for substr_replace:
$string = "Hello World; lorem ipsum dolor";
$pos = strpos($string, ";");
if ($pos !== FALSE) {
$string = substr_replace($string, "", $pos);
}
var_dump($string);
part extraction
That was most of the other answers. Here is another alternative function to do this: you are probably looking for a strstr()function : $ result = strstr ($ string, ";", true);
, true, $string, ( ) ";".
:
$string = "Hello World; lorem ipsum dolor";
$result = strstr($string, ";", true);
var_dump($result); // string(11) "Hello World"
, , ";" , , :
$result = strstr("$string;", ";", true);
, strpos(), FALSE.