gpt4 book ai didi

php : replace image src path using php script

转载 作者:行者123 更新时间:2023-11-29 09:44:40 28 4
gpt4 key购买 nike

我想创建 php 脚本来更新 img src 路径。

旧结果:

<a href="http://example.com" target="_blank"><img src="{{media url=''}}wysiwyg/images/img_07.jpg" border="1">

预期结果:

<a href="http://example.com" target="_blank"><img src="{{media url='wysiwyg/images/img_07.jpg'}}" border="1">

我使用了下面的代码:

<?php
$servername = "localhost";
$username = "root";
$password = "testing";
$dbname = "database";

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

$sql = "SELECT * FROM table_nm WHERE attribute_id = 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo htmlentities($row["value"]) . "<br>"; //old result text display from here.
}
} else {
echo "0 results";
}
$conn->close();
?>

我需要改变什么才能获得预期的结果?

最佳答案

您可以尝试一下以获得预期的结果

$patterns = ["'}}","jpg","png","jpeg","gif"];
$replacements = ["","jpg'}}","png'}}","jpeg'}}","gif'}}"];
$row["value"] = str_replace($patterns, $replacements, $row["value"]);

关于php : replace image src path using php script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55902390/

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