View Full Version : Are dynamic links possible?
kreven
04-23-2007, 03:31 AM
Hi,
Is there a script that can allow you (maybe using XML or something) to insert a list of words in a file and then, if those words appear on your page it will automatically make them linkable to a specific place you want to go?
I have been searching, but I dont know what exactly the name is being used for this situation so I havent been very fortunate to find anything.
Any help/info would be greatly appreciated!! Thanks!!
Kreven
djr33
04-23-2007, 05:47 AM
I'm sure it's possible... somehow.
There are some very vague aspects of your question:
1. "insert".... user? you? before processing? textbox on the page? on the server? client's computer? etc.
2. How do they relate... if the word appears on the page, then... it goes to the same page? A page like "word.htm"? a page you set by word (as pairs of words/pages)?
3. Would these pages need to be generated? dynamic? pre-exist?
Also, for the list of words, could this be specifically set, or would it need to be easy to change (by you? the user?)
nwalton
04-23-2007, 11:52 PM
I think I got some malicious code in my browser once that did that. Every page I pulled up would have words highlighted, and if you clicked on them it took you to some advertiser's site. Very weird. And annoying. I had to reset all of my browser settings/prefs to get rid of it.
kreven
04-24-2007, 01:15 AM
I'm sure it's possible... somehow.
There are some very vague aspects of your question:
1. "insert".... user? you? before processing? textbox on the page? on the server? client's computer? etc.
I would like to, not the user. For example, I have a page with various countries information and if the word, "Japan" is in the text of the webpage I've created, I want it(the word "Japan") to appear as a link to the "japan/index.html" page and so forth for other countries. And I it would be controlled from the server on my side. (therefore would work for anyone that visited the site)
2. How do they relate... if the word appears on the page, then... it goes to the same page? A page like "word.htm"? a page you set by word (as pairs of words/pages)?
I think its answered above. :D
3. Would these pages need to be generated? dynamic? pre-exist?
Also, for the list of words, could this be specifically set, or would it need to be easy to change (by you? the user?)
I'm not sure what you would call it, but I dont want to have to manually do it all the time because that top page will be changing all the time with those words (its a whats new area).
I hope my description can be understood. I have a feeling I've seen it around as well (but my intention isnt to use it as spam or whatever).
Thanks again!
Kreven
Its similar to this option: "Automatically parse links in text" is similar I think but instead of when it sees http or www or whatever it will be a country and link to that countries page (which hopefully can be entered in somewhere).
djr33
04-24-2007, 03:07 AM
When I said generated dynamically, I wasn't asking about the links. I'm aware that the text must be parsed for those. What I was asking about was the list.
Anyway.... here's how I think it should work...
Here is some PHP code for your page;
Just fill in the blanks as you wish:
<?php
$words = array(
array('apple','http://apple.com'),
array('orange','http://orange.com'),
array('banana','http://banana.com')
); //setup your words/urls
//copy pattern above
//last one needs no comma
$f = file_get_contents('**thispage***.php'); //get contents of this page
list($f,$null) = explode('/*END*/ ?>',$f); //take of this php from top
list($f,$null) = explode("/n",$f); //get rid of extra line
foreach($words as $word) {
$f = str_replace($f,$word[0],'<a href="'.$word[1].'">'.$word[0].'</a>');
}
//replace all words with links
echo $f; //output page
die(); //end script execution
//and don't output rest of page
//it's already output by script
/*END*/ ?>
<html>
the rest of your page goes here
whatever you want
Oh, and you can't use any more PHP on the page
or it would get complex
there are ways around it, though
but let me know if you need that,
and we cant work it out
Also, this would cause issues if
the keywords are in the code
like if you used 'div' as a keyword
it would parse <div> to be a link
kreven
04-24-2007, 03:13 AM
Brilliant!! :D thanks! I will try this right away, this looks like it can work!!
Not a php pro but I know coding in general. (I can read, understand and edit but never been good at creating from scratch)
djr33
04-24-2007, 03:15 AM
Good. I hope it does work.
I'm a bit distracted right now.
I think the basic structure is there, might need some work. Lemme know.
Also, the huge issue here is dealing with the fact that it doesn't parse html... so it doesn't know what is a word and what is not, and doesn't parse other PHP. It's complex. It would be possible to write this, but it would be a lot more work.
I'd suggest using a javascript method (which I can't write) if you need other server side code on the page (though having it skip <?php and ?> is easy... not getting it to perform those, though).
As for parsing the html... I'd suggest looking for a base script on which it could be built.
kreven
04-24-2007, 03:25 AM
Well as of now it is pure HTML and has no plans of adding any more scripts to that page. (Only script it has is basic rollover button JS)
Anyway I will try it and see how it goes!!
Kreven
djr33
04-24-2007, 03:27 AM
Sure.
One way to cheat and not fully require that it be parsed as html to check if the word is a word, not code, would be to check it's placement:
" word "
"/nword."
" word!"
etc/mix thereof
kreven
04-24-2007, 03:38 AM
Error message popped: Fatal error: Call to undefined function: file_get_contents() in /index2.php on line 10
This is line 10:
$f = file_get_contents('index2.php'); //get contents of this page
Don't think it liked this function. Believe the php version im using is 5.0. If it was version 4.0 would there be a problem?
kreven
04-24-2007, 04:23 AM
Researched a bit, appears I need 4.30 or above to use that function. I'll see what I can do about getting my server updated. Will post more later.
Kreven
djr33
04-24-2007, 04:44 AM
never had a problem, but never used it with below 4.3, actually, so no clue.
check php.net (search in the function box) for more info if needed.
If not, it would be possible with a few roundabout functions... but that's a pain.
I'd gues more that it might be security not allowing that function/use.
kreven
04-24-2007, 04:57 AM
Hmm, just installed Apache/PHP on my computer and tested the file (using PHP 5.2.1) and got in interesting result.
First off this is the code I used:
<?php
$words = array(
array('PCL :','http://apple.com'),
array('DESIGN','http://orange.com'),
array('report','http://banana.com')
); //setup your words/urls
//copy pattern above
//last one needs no comma
$f = file_get_contents('index2.php'); //get contents of this page
list($f,$null) = explode('/*END*/ ?>',$f); //take of this php from top
list($f,$null) = explode("/n",$f); //get rid of extra line
foreach($words as $word) {
$f = str_replace($f,$word[0],'<a href="'.$word[1].'">'.$word[0].'</a>');
}
//replace all words with links
echo $f; //output page
die(); //end script execution
//and don't output rest of page
//it's already output by script
/*END*/ ?>
Then after this is the Doctype and Html.
Here is a bit of the HTML code to give you an idea:
<div class="txt_box_outer">
<!--Whats New CONTENTS START -->
<div>May 15th, 2007 - <span class="redText"> UPDATE!</span></div>
<ul class="txt_box_inner">
<li>NEW SITE RENEWAL DESIGN CREATED!! </li>
</ul>
<div style="margin-top:10px;"></div>
<div>April 25th, 2007 - <span class="blueText"> UPDATE!</span></div>
<ul class="txt_box_inner">
<li>PCL : <a href="pcl/index.html#pr">PR</a> - Media Report</li>
</ul>
<!--Whats New CONTENTS END -->
</div>
It didnt print out the HTML code but just "report" and it was linked to 'http://banana.com' which is correct but only that appeared..
Any ideas?
kreven
04-24-2007, 05:03 AM
added image
djr33
04-24-2007, 05:07 AM
I'd need to see the output code to really understand what is going on. (The resulting html, that is)
kreven
04-24-2007, 05:28 AM
perhaps you missed the pic posted 2 post up?? :)
djr33
04-24-2007, 06:34 AM
The image doesn't help. I see that "report" is output, as, it seems, a link. But I have no idea what text is actually there, in the code. I need to see the source.
Either link or post the output source code.
kreven
04-24-2007, 06:37 AM
Apologies for the misunderstanding.
This source code printed when doing "View->Source" is the following:
<a href="http://banana.com">report</a>
Nothing else but that comes out. :eek:
techno_race
05-11-2007, 03:05 AM
Phpはサーバー側面顧客側面ではなく、ように実際に作りの感覚である。
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.