<分区>
当他得到“;”时,我需要将一些字符串替换到字符串的末尾或切断字符串签名?
我正在尝试,但它不起作用:
$string = "Hello World; lorem ipsum dolor";
$string = str_replace(";","\0",$string);
echo $string; //I want the result is "Hello World"
<分区>
当他得到“;”时,我需要将一些字符串替换到字符串的末尾或切断字符串签名?
我正在尝试,但它不起作用:
$string = "Hello World; lorem ipsum dolor";
$string = str_replace(";","\0",$string);
echo $string; //I want the result is "Hello World"
最佳答案
这应该适合你:
<?php
$string = "Hello World; lorem ipsum dolor";
echo $string = substr($string, 0, strpos($string, ";"));
?>
输出:
Hello World
关于PHP 字符串替换为字符串结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27621028/