473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Importing an external relative link to your page

shishisu
I figure this might be a fun challenge to some of you out there...
I appreciate all the help. Thanks in advance.

Here we go...
I have 2 web page (on different servers) I am working on. Here, we'll call them Page-A and Page-B.

I want to save some work by only having to maintain 1 web page and the changes made to source page will get reflect onto the other one. In this case, Page-A is the source and Page-B should just have a content grabbing PHP script.

I thought of using ob_get_contents(); grabbing Page-A's HTML code and insert them into Page-B. However, doing that means I will have to create a whole mirror set of files+images on both Page-A's server and Page-B's server.

Since Page-A has both links to other domains (absolute URLs) and links to local page/files (relative URLs). The codes needed here will have:

1. A way to find all the URLs on Page-A

2. Determine if it is a relative URL or absolute URL:

3a. If it is an absolute URL, Page-B just go ahead and grab that URL,

3b. If it is a relative link, Page-B will have to convert that link into absolue URL (adding Server-B's domain name to the URL).
Jun 6 '07 #1
5 2107
pbmods
5,821 Expert 4TB
Changed thread title: Removed superfluous 'fun challenge'.

Heya, shishisu. Welcome to TSDN!

Sounds like an ambitious project. How far have you gotten?
Jun 6 '07 #2
jx2
228 100+
well its not difficult all u need its some regularexpresions :-)
but i dont have your code and it would take more then a while :-)

good luck
Jun 6 '07 #3
hahah thanks, I thought most challenges should be fun.

what I have so far...

I can now import sections of the HTML contents from Page-A and display onto Page-B by using the output-buffer.

I figured out how to explode a URL and append the server domain.

Now my trouble is just writing the code to:
1. find all the href and img tags
2. grab these link paths
3. figure out if they are local links (relative) or external links (absolute).
Jun 7 '07 #4
pbmods
5,821 Expert 4TB
Ok. Here's what I'm thinking:
  1. preg_split your HTML by '/<a|img/' (this assumes well-formed HTML; you might need to get a little tricky... '/<\s*(a|img)/i'). Then you know where your a|img tags are.
  2. preg_match each element in the resulting array (starting with the 1st [not 0th] element) for... hm. Something like '/(http:\/\/www\..+?\.\w+)?([^"\s])*/'. This is a REALLY rough (and inefficient!) regexp; you can probably come up with a better one.
  3. In terms of figuring out which is which... hm. You could preg_match_all the original string again to determine the order of the a|img tags. You could check the extension of the file in the URL (not much of a guarantee these days). I'm out of ideas. Assuming, of course, that knowing which are HREFs and which are SRCs is important.
Jun 7 '07 #5
I am thinking after finding the tags, I will do a check to see if it is a '/' or '.' <-- shows that they are relative links.

if they are relative, then I will combine it with Server-B's domain name.
Jun 7 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Philipp Lenssen | last post by:
Given a page's URL, and a URL in a link found inside it, how can I resolve this link-URL to become an absolute URL? function getAbsoluteUrl($baseurl, $relativeurl); Examples: Page: ...
2
by: Catherine Lynn Wood | last post by:
I need to know how to overlap DIV content within 'relative' associated rendering. I am building div layers in the middle of a page and when I set positioning to absolute in the CSS, it references...
2
by: Aarono Brown | last post by:
In the following html page, I'm using a stylesheet to move everything in the body over five percent, and then move the h1 heading back over to the left margin. On IE 6 (W2K & 98) the relative...
8
by: Nicolás Lichtmaier | last post by:
Hi, some time ago I've written an article about this issue. It explain some differences in Explorer's and Mozilla's JavaScript/DOM. It has recently changed its URL, This is the new one: ...
3
by: js5895 | last post by:
Hi, Where can I find a free link and page counter for my web site, it's road runner, so basically theres no server-side functionality, lol Thanks. Note: If this is the wrong group for this...
6
by: dark.peony | last post by:
Hi, (--1--) I'm trying to find a way to jump to a link (<a href="ref"></a>) in a page that is generated with javascript. The source view of the page only shows the javascript methods. The...
2
by: dgmoore | last post by:
I have a web site hosted on worldwide LAN A. The web site links to documents on a server on LAN B, which has mirror sites all over the world. Users at remote locations are able to access only files...
1
by: simonZ | last post by:
I have image folder in root folder of my application and one image inside it: /images/image.jpg How can I access to this image from all my subfolders using relative link? something like:...
0
by: Ryan | last post by:
Hi everyone, I have enabled my webparts site to use ajax by simply using updatepanels. This worked fine. Now I tried to enable drag and drop for the webparts so I added some stuff to the web...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.