I need to replace some string to end of string or cut the string when he got ";" sign?
Im trying but it doesnt work :
$string = "Hello World; lorem ipsum dolor";
$string = str_replace(";","\0",$string);
echo $string; //I want the result is "Hello World"
This should work for you:
<?php
$string = "Hello World; lorem ipsum dolor";
echo $string = substr($string, 0, strpos($string, ";"));
?>
Output:
Hello World
You need to split the string with ;
and get first element from the returned array (it will always have at least one entry).
echo explode(';', $string, 2)[0];
explode()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With