PHP 字符串替换为字符串结尾

标签 php string

<分区>

当他得到“;”时,我需要将一些字符串替换到字符串的末尾或切断字符串签名?

我正在尝试,但它不起作用:

$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/

相关文章:

php - 如何在不让字符串被引号包围的情况下使用 PDO::quote?

php - 使用 PDO 在 1 个查询中更新多个表记录

C - 不打印出整个字符串

java - 如果性能很重要,我应该使用 Java 的 String.format() 吗?

c - 从 fgets() 输入中删除尾随换行符

c - 如何使用单词 'int' ,但作为字符串而不是 C 中的数据类型?

PHP for 循环显示奇怪的结果

php - 在 PHP 中读取非常大的文件

c++ - std::string 到 char*

php - 将 max_input_vars 3000 添加到我的 .htaccess 文件和 php.ini 不工作