gpt4 book ai didi

php - 如何通过 PHP/MySQL 替换第一个点之后的所有文本

转载 作者:行者123 更新时间:2023-11-29 11:48:03 25 4
gpt4 key购买 nike

我想使用 php 文件替换第一个点之后的所有文本。对于我现在使用的代码:

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "UPDATE pm_videos SET `description` = REPLACE( `description` ,'Facebook', '')";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully with Facebook, ";
} else {
echo "Error updating record: " . $conn->error;
}

$sql = "UPDATE pm_videos SET `description` = REPLACE( `description` ,'Twitter', '')";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully with Twitter, ";
} else {
echo "Error updating record: " . $conn->error;
}

$conn->close()

...但我想替换/删除第一个点之后的所有内容。

例如:

之前:

Asia's Got Talent Grand Winner El Gamma Penumbra performs on ASAP stage. Subscribe to ABS-CBN Entertainment channel! - Watch the full episodes of ASAP 20 on TFC.TV and on IWANT.TV for Philippine viewers, click: Visit our official website! Facebook: Twitter: Instagram:

之后:

Asia's Got Talent Grand Winner El Gamma Penumbra performs on ASAP stage.  

最佳答案

您可以使用 PHP 函数 strpos 在字符串 stripos() 中查找点。接下来,您必须将位置发送到 substr(),其中第一个参数字符串,第二个参数是 start(在您的情况下为 0)和最后一个资助位置 strpos。

$result = substr($string, 0, stripos($string, "."));

关于php - 如何通过 PHP/MySQL 替换第一个点之后的所有文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34573386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com