且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

修复curl页面上的链接

更新时间:2023-12-03 09:33:34

这是因为cURL响应会带来该URL的所有html代码,并应用到您的当前页。因此,返回您网页的所有链接都链接到目标网址(即 http://www.mybroadband。 )。这会在响应中产生类似的结果:

That is because the cURL Response brings all the html code from that URL and applies into your current page. Thus, all the links returned to your page are linked to the destination url (which is http://www.mybroadband.co.za/). That results in something like this in the response:

<a href="http://www.mybroadband.co.za/xyz">XYZ</a>
<a href="http://www.mybroadband.co.za/abc">ABC</a>

因此,当您点击这些链接,它会引导您到 http ://www.mybroadband.co.za/something 。你需要的不是重定向到这些页面,而是显示在localhost页面的内容?假设我是对的。

Thus, when you click on these links, it will direct you to http://www.mybroadband.co.za/something. What you need is not to be redirected into those pages, but instead display the content in your localhost page? Assuming that I'm right.

因此,为了解决这个问题,您需要编辑curl响应,其中转换上面的HTML锚标签(链接):

So, in order to solve this problem, you need to edit the cURL Response in which you transform those HTML anchor tags (links) above into:

<a onClick="getPage('http://www.mybroadband.co.za/xyz')">XYZ</a>
<a onClick="getPage('http://www.mybroadband.co.za/abc')">ABC</a>

然后只需编写一个 getPage($ link)函数,使用AJAX从$ link请求页面并返回,就像你所做的一样。

Then just code a getPage($link) function in Javascript, using AJAX to request the page from $link and return, just like what you did.