Files
html/api/ambre-fix-regex-final.php
2026-04-22 01:55:03 +02:00

35 lines
1.1 KiB
PHP

<?php
header("Content-Type: application/json");
$path = "/var/www/html/wevia.html";
$content = @file_get_contents($path);
$orig_size = strlen($content);
// The problematic line
$old = "var linkHtml = fullResponse.replace(new RegExp(finalFileUrl, \x27g\x27), \x27<a href=\"\x27+finalFileUrl+\x27\"";
$has_old = strpos($content, $old);
if ($has_old === false) {
echo json_encode(["error"=>"pattern not found", "size"=>$orig_size]);
exit;
}
// Escape function: replace all regex-special chars with \\char
// The fix: use a simple string.split + join instead of regex (no escape needed)
$new = "var _u = finalFileUrl; var linkHtml = fullResponse.split(_u).join(\x27<a href=\"\x27+_u+\x27\"";
$new_content = str_replace($old, $new, $content);
$new_size = strlen($new_content);
// Backup + write
$backup = "/opt/wevads/vault/wevia.html.GOLD-" . date("Ymd-His") . "-regex-split-fix";
@copy($path, $backup);
$wrote = @file_put_contents($path, $new_content);
echo json_encode([
"orig_size" => $orig_size,
"new_size" => $new_size,
"delta" => $new_size - $orig_size,
"wrote" => $wrote,
"backup" => basename($backup),
]);