Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Replacing links on a page
Old 09-30-2007, 02:01 AM Replacing links on a page
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Although it can be done in javascript, I'm interested to how this can be done in PHP...

Basically, before you output an html document, you buffer it and remove all links which point to the same html document. Anyone who has worked in usability will know what i am talking about.

The idea is that a page should never link to itself.

Anyone have an idea?
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
 
Register now for full access!
Old 09-30-2007, 02:04 AM Re: Replacing links on a page
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
By the way, for anyone who doesn't know what i'm talking about, a quick google has brought up http://snook.ca/archives/javascript/clear_links_to_1/ which does it in javascript.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 10-01-2007, 02:05 AM Re: Replacing links on a page
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Which of the moments is your problem, buffering the page or replacing links?

Buffering the page is rather simple, rtfm ob_start() and corresponding functions.

Replacing links is much more complicated, especially if you do not know much about the format of links output. Since link to the current page can be presented in one of following forms:
- http://full.domain.name/some-folder/url-to-page.html
- /path-from/site-root/to-page.html
- relative-path/from-current/folder-root.html
- only-page.html
- ?page=2&something=else
the task becomes really hard, because you have first to represent all links into the same form, e.g. into fully qualified URL and then filter out the link to current page. In JS this can be done much easier because the browser's JS engine automatically represents all urls within the page into such form.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-01-2007, 03:47 AM Re: Replacing links on a page
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
The problem is with replacing links (thanks for the excellent answer).

Representing the links into fully qualified URL's is not a problem... its identifying them and removing them which is.

Any ideas?
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 10-01-2007, 05:36 AM Re: Replacing links on a page
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Okay, i think i found the solution...

http://www.php.net/manual/en/functio...lace.php#64213

combined with

http://www.php.net/manual/en/functio...e-callback.php

Right?
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 10-01-2007, 05:45 AM Re: Replacing links on a page
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Yes, that could help
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-02-2007, 03:12 PM Re: Replacing links on a page
Average Talker

Posts: 20
Name: Bling
Trades: 0
i have a method if that does not work
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
idkwot is offline
Reply With Quote
View Public Profile Visit idkwot's homepage!
 
Old 10-05-2007, 02:27 AM Re: Replacing links on a page
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Sorry i didn't respond any earlier... i didn't get any notifications.

idkwot, before i try to remake the wheel, what's your method?
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 10-05-2007, 02:41 AM Re: Replacing links on a page
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I would use PHP's DOM extension.
http://www.php.net/manual/en/ref.dom.php

You grab the page content with ob_* functions, load the html as a dom document, and then, you can parse it like you do in javascript, with a getElementsByTagName('a').

Looks like the most flexible way to go.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-05-2007, 06:18 AM Re: Replacing links on a page
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Any examples?
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 10-05-2007, 07:31 AM Re: Replacing links on a page
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Readily made, no...
I just found out this extension some weeks ago, but never used it.

But it should allow to do the same as you can in javascript, with the same calls (or almost).
And I always find that if you can avoid regexp to do an action, you should avoid it, may it be just for the readability of the code by someone else.
If it's not at the cost of too much load, of course. You have to balance that.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-05-2007, 08:18 AM Re: Replacing links on a page
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Thanks.

I've had a go and googled around for other's... not looking good i'm afraid!
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 10-05-2007, 11:06 AM Re: Replacing links on a page
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
I think i'm going to stick to js for now.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Reply     « Reply to Replacing links on a page
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.36987 seconds with 12 queries