Я пытаюсь заменить исходники (src) для сценария и тегов img.У меня есть «../filename.js», и я хочу избавиться от 2 точек, как мне это сделать?
<?php
$file_path = content_url() . '/help/WS/WAS_B.htm';
$contents = wp_remote_fopen( $file_path );
$help_path = content_url() . '/help/';
$find = array(
'#<script type="(.*?)" src="(.*?)">(.*?)</script>#is',
'/<img src="(.*)" alt="(.*)" style="(.*)" \/>/i'
);
$replace = array(
'<script type="${1}" src="' . $help_path . ' ${2}"></script>',
'<img src="' . $help_path . '${1}" alt="${2}" style="${3}" />'
);
$preg_rep = preg_replace($find, $replace, $contents);
?>
Это ссылка и изображение, над которым я работаю:
<img src="../Links/WAS_PIC_ControlBox-1-2-3.jpg" alt="WAS-Betjeningsboks-1-2-3"
style="border: none; margin-left: 20px; margin-right: 0px; margin-top: 0px; margin-bottom: 0px;" border="0">
<script type="text/javascript" src="../ehlpdhtm.js"></script>
Вывод, который я хотел бы получить, должен быть таким:
<img src="http:xxx.com/wp-content/help/Links/WAS_PIC_ControlBox-1-2-3.jpg" alt="WAS-Betjeningsboks-1-2-3"
style="border: none; margin-left: 20px; margin-right: 0px; margin-top: 0px; margin-bottom: 0px;" border="0">
<script type="text/javascript" src="http:xxx.com/wp-content/help/ehlpdhtm.js"></script>