Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检测html代码字符串中的文件路径_Html_Detect_Filepath - Fatal编程技术网

如何检测html代码字符串中的文件路径

如何检测html代码字符串中的文件路径,html,detect,filepath,Html,Detect,Filepath,我需要使用ajax读入一系列HTML代码,并重构字符串中找到的每个文件路径 例如: 我需要检测“../../images/home.jpg” 并将其更改为“http://www.mywebsite.com/report/images/home.jpg“ 我实际上是在做一个仪表板。使用iframe在仪表板中显示内容会降低性能。为了不使用iframe,我打算读入目标URL的html代码字符串。但这里唯一的因素是,如果任何图像、javascript或css的文件路径不是绝对路径,我的仪表板将无法显示

我需要使用ajax读入一系列HTML代码,并重构字符串中找到的每个文件路径

例如:

我需要检测“../../images/home.jpg” 并将其更改为“http://www.mywebsite.com/report/images/home.jpg“

我实际上是在做一个仪表板。使用iframe在仪表板中显示内容会降低性能。为了不使用iframe,我打算读入目标URL的html代码字符串。但这里唯一的因素是,如果任何图像、javascript或css的文件路径不是绝对路径,我的仪表板将无法显示

请给出您的想法,您将如何检测html代码字符串中的文件路径,或者您知道是否存在任何现有库

下面是我正在阅读的一个简单的html代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"><title>
    Web Report: Customer Complains
</title><link rel="stylesheet" type="text/css" href="../../../css/Concept1.css" /></head>
<style type="text/css">

</style>
<body>
        <div class="SectionTitleContainer1">
            <div style="text-align: left;" class="SectionTitle">
                Customer Complaints
            </div>
        </div>
    <table cellspacing="0" cellpadding="5" style="width: 100%;" border="0">

        <tr>
            <td width="1%" align="left">
                <a>
                Refund 

                    </a>
            </td>
            <td width="1%" style="text-align: right">139</td>
            <td align="left" style="">
                <img src="../../../images/tile-horiz-bar.png" style="height: 10px; width: 100px" />
            </td>
        </tr>

        <tr>
            <td width="1%" align="left">
                <a>
                Appointment Rescheduled/Delayed 

                    </a>
            </td>
            <td width="1%" style="text-align: right">96</td>
            <td align="left" style="">
                <img src="../../../images/tile-horiz-bar.png" style="height: 10px; width: 69px" />
            </td>
        </tr>                
    </table>
    </body>
</html>

网络报告:客户投诉
顾客投诉
退款
139
预约重新安排/延迟
96

经过长时间的发现,我了解到,如果需要两个不同的系统来显示相同的UI,我们应该将图像文件(或任何其他脚本文件)放在服务器的公共目录中。应授予Web应用程序访问服务器本地目录中文件的适当权限。保存图像文件的目录不应受到保护,也不应公开(如有必要)。

经过长时间的发现,我了解到,如果需要两个不同的系统来显示相同的UI,我们应该将图像文件(或任何其他脚本文件)放在服务器内的公共目录中。应授予Web应用程序访问服务器本地目录中文件的适当权限。保存图像文件的目录不应受到保护,也不应向公众公开(如有必要)。

请添加输入html片段的完整示例。如果格式正确,可以使用xslt解决这个问题。读取的html代码不是固定的。因此,我必须检测诸如javascript的“src”和css的“url(“”)”之类的关键字。但在开始编写代码之前,我想听听更多人的意见。=)请添加输入html片段的完整示例。如果格式正确,可以使用xslt解决这个问题。读取的html代码不是固定的。因此,我必须检测诸如javascript的“src”和css的“url(“”)”之类的关键字。但在开始编写代码之前,我想听听更多人的意见。=)