473,734 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Importing an external relative link to your page

shishisu
3 New Member
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 2154
pbmods
5,821 Recognized Expert Expert
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 New Member
well its not difficult all u need its some regularexpresio ns :-)
but i dont have your code and it would take more then a while :-)

good luck
Jun 6 '07 #3
shishisu
3 New Member
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 Recognized Expert Expert
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
shishisu
3 New Member
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
1702
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: http://www.example.com/index.html Link: /about.html Result: http://www.example.com/about.html
2
12037
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 back to 0,0 on the entire page. If I set it to relative, the div layers will not overlap as needed. I prefer to avoid javascripting an 'innerHTML' re-write of a single div and would instead like to build two layers that can reside at the same...
2
2468
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 link (fragment identifier) only works if the heading text is wider than five percent of the window size. (In other words, change the lowercase letter "l" used below into something longer -- or make the window sufficiently narrow -- and it'll start...
8
2942
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: http://www.reloco.com.ar/mozilla/compat.html Bye! PS: I hope it's useful to someone. I would appreciate any comments and suggestions!
3
1539
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 message, could you please redirect me, thanks and sorry.
6
2931
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 HTML is *not* visible in the source view.
2
1383
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 that are hosted on the mirror server that serves their region. Is there any way to employ hyperlinks in my web pages that will link to files on the mirror server for the region in which the particular user happens to be located? Thanks
1
1053
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: ~/images/image.jpg where ~ means root folder of my application.
0
1450
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 config: http://blogs.neudesic.com/blogs/david_barkol/archive/2006/03/22/82.aspx I have a masterpage with no webpart stuff and child pages with all the webpartzones and the custom webpartmanager. I have tried putting the
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.