我想创建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 - php:使用php脚本替换图像src路径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55902390/