我想用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()
,其中第一个param字符串、第二个param是开始(在您的情况下为0)和最后一个资助仓位strpos。
$result = substr($string, 0, stripos($string, "."));