如何使所有src字符串在PHP中全局化? [英] How to make all src strings global in PHP?
问题描述
我正在用PHP编写一个Web浏览器,用于不支持多选项卡浏览的设备(例如Kindle).目前,我正在使用file_get_contents()阅读页面源代码,然后将其回显到页面中.我的问题是许多页面使用本地引用(例如< img src ='image.png>'),因此它们都指向不存在的页面.我想做的是找到所有src和href标记,并将完整的Web地址添加到任何不以"http://"或"https://"开头的地址.我该怎么办?
I am writing a web browser in PHP, for devices (such as the Kindle) which do not support multi-tab browsing. Currently I am reading the page source with file_get_contents(), and then echoing it into the page. My problem is that many pages use local references (such as < img src='image.png>'), so they all point to pages that don't exist. What I want to do is locate all src and href tags and prepend the full web address to any that do not start with "http://" or "https://". How would I do this?
推荐答案
添加<base href="http://example.com/" />
页面顶部
此将帮助您将其插入到<head></head>
部分
this will help you insert it to the <head></head>
section
这篇关于如何使所有src字符串在PHP中全局化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!