diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php
index 0b8689dca4d..93ad59da63c 100644
--- a/htdocs/core/lib/website.lib.php
+++ b/htdocs/core/lib/website.lib.php
@@ -98,7 +98,7 @@ function dolWebsiteOutput($content)
function dolWebsiteReplacementOfLinks($website, $content)
{
// Replace php code. Note $content may come from database and does not contains body tags.
- $content = preg_replace('/<\?php[^\?]+\?>\n*/ims', '...php...', $content);
+ $content = preg_replace('/<\?php((?!\?>).)*\?>\n*/ims', '...php...', $content);
// Replace relative link / with dolibarr URL
$content = preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageid='.$website->fk_default_home.'"', $content, -1, $nbrep);