Closed Thread Icon

Topic awaiting preservation: replacing things in the url - php (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=11962" title="Pages that link to Topic awaiting preservation: replacing things in the url - php (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: replacing things in the url - php <span class="small">(Page 1 of 1)</span>\

 
DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 12-21-2001 16:16

Hi, and happy holidays!

Now, this is over my head...
I've got a site on one physical server that serves a php/mysql-portal, some of the content is drawn from another physical server that runs lotus notes.

I've got a script that works, but is resource intensive to say the least, and it's pretty much hardcoded.
Looks like this:

code:
function getNotes($notesurl){
openTable();

//defines variables to use as part of url later on
$fileurl = "http://rohan/BullAB";
$fileurl2 = "http://rohan";
$baseurl = "http://rohan/";
$imgurl = "<img src=\"http://rohan/BullAB";
$imgurl2 = "<img src=\"http://rohan";
$imgurl3 = "<img src=\"http://rohan/";

//replaces wierd lotus-combinations in the url that will disrupt the getting of the file from notes
$notesurl = eregi_replace("<X>Open",'?Open',$notesurl);
$notesurl = eregi_replace("<Y>Search",'?Search',$notesurl);
$notesurl = eregi_replace("<Z>",'&',$notesurl);
$notesurl = eregi_replace("<A>",'/Intranet+document.nsf/',$notesurl);
$notesurl = eregi_replace("<B>",'/Telefoner+FAQ.nsf',$notesurl);
$notesurl = eregi_replace("<C>",'/IEDB+Docs.nsf',$notesurl);
$notesurl = eregi_replace("<D>",'/By+Category',$notesurl);
$notesurl = eregi_replace("/Intranet dokument.nsf/",'/Intranet+dokument.nsf/',$notesurl);
$notesurl = eregi_replace("/Telefoner FAQ.nsf",'/Telefoner+FAQ.nsf',$notesurl);
$notesurl = eregi_replace("/IEDB Docs.nsf",'/IEDB+Docs.nsf',$notesurl);
$notesurl = eregi_replace("/By Category",'/By+Category',$notesurl);

//just a check...
print($notesurl);

//get the file from notes
$nsfile = file("$baseurl$notesurl");

//loop through the file from notes and rebuild the urls since they will be shown from another machine
for($i=0; $i < count($nsfile);$i++){
//imagepaths...
$nsfile[$i] = eregi_replace('<IMG SRC="/BullAB',"$imgurl",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<IMG SRC="/local',"$imgurl2/local",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<IMG SRC="/idp',"$imgurl2/idp",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<IMG SRC="idp',"$imgurl3idp",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<IMG SRC="/Samm',"$imgurl2/Samm",$nsfile[$i]);

if(strstr($nsfile[$i],"\$FILE")==false){
//make links on page point to script
$nsfile[$i] = eregi_replace('<A HREF="/BullAB',"<A href=\"getnotes.php?noteslink=BullAB",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="http://rohan/BullAB',"<A href=\"getnotes.php?noteslink=BullAB",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="http://rohan/',"<A href=\"getnotes.php?noteslink=",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="http://infranet/local',"<A href=\"getnotes.php?noteslink=local",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="http://infranet',"<A href=\"getnotes.php?noteslink=",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/local',"<A href=\"getnotes.php?noteslink=local",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/idp',"<A href=\"getnotes.php?noteslink=idp",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/Samm',"<A href=\"getnotes.php?noteslink=Samm",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/Forsaljning',"<A href=\"getnotes.php?noteslink=forsaljning",$nsfile[$i]);
}else{
//correct other links
$nsfile[$i] = eregi_replace('<A HREF="/BullAB',"<A href=\"$fileurl",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="http://rohan/BullAB',"<A href=\"$fileurl",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="http://infranet/local',"<A href=\"$fileurl2/local",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="http://infranet',"<A href=\"$fileurl2/",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/local',"<A href=\"$fileurl2/local",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/idp',"<A href=\"$fileurl2/idp",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/Samm',"<A href=\"$fileurl2/Samm",$nsfile[$i]);
$nsfile[$i] = eregi_replace('<A HREF="/forsaljning',"<A href=\"$fileurl2/forsaljning",$nsfile[$i]);
}
//if there is a searchform, make it open the result in new window
if(strstr($nsfile[$i],"ACTION")!=false){
$nsfile[$i] = eregi_replace('ACTION="/BullAB',"ACTION=\"$fileurl",$nsfile[$i]);
$nsfile[$i] = eregi_replace("SearchView",'SearchView" target="_blank"',$nsfile[$i]);
}
$nsfile[$i] = eregi_replace("/icons","$baseurl/icons",$nsfile[$i]);
$nsfile[$i] = eregi_replace("\?Open",'<X>Open',$nsfile[$i]);

//if no form, correct the urls so notes will recognize them
if(strstr($nsfile[$i],"ACTION")==false){
$nsfile[$i] = eregi_replace("\?Search",'<Y>Search',$nsfile[$i]);
}
$nsfile[$i] = eregi_replace("&",'<Z>',$nsfile[$i]);
$nsfile[$i] = eregi_replace("/Intranet+dokument.nsf/",'<A>',$nsfile[$i]);
$nsfile[$i] = eregi_replace("/Telefoner+FAQ.nsf",'<B>',$nsfile[$i]);
$nsfile[$i] = eregi_replace("/IEDB+Docs.nsf",'<C>',$nsfile[$i]);
$nsfile[$i] = eregi_replace("/By+Category",'<D>',$nsfile[$i]);

//print the code to the page
print($nsfile[$i]);
}
closeTable();
}
print("<b>Följande information hämtas direkt från Lotus Notes.</b>");

//call the function recusivly for the links I've created in the script
getNotes("$noteslink");


(it's a hack and it eats the processor, I know, but this site is low traffic and sits alone on a server...)

So far so good, it works, but...

The thing is that as admins of the portal add new noteslinks, there will be new, strange combinations of databasenames in notes and so on that this hardcoded script doesn't handle, so I'll have to go in and add more lines...

In essence, there might be "+", " ", "&","?", "-", in the urls I encounter that I need to handle as I step into the script, and then reverse it so notes will recognise it as I call the path again...

I've tried using the same principle as above to replace just the offending_chars but that breaks everything totally except for the "&", that works. I've got a feeling that the ? and + and - means something special in the pattern matching since I have to escape them if they are alone or in the beginning, but if they are escaped, they won't be recognized in the string...

I don't know squat about regular expressions, perl or otherwise so I have no clue whatsoever on how to fix this.
Anyone have an idea?

I can't put up the page since it's on the intranet, but any tips are more than welcome.
Happy holidays!
/Dan


-{ a vibration is a movement that doesn't know which way to go }-

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 12-22-2001 00:03

Your code gives me a headache, perhaps you could just post a few examples of URLs and how you want them changed.

Anyway, if you are not using regular expressions (ie. literal match) then str_replace() will give you much better performance and solve some of your character escaping problems.

Speaking of escaping, you said the characters won't be recognized if you escape them, yet that is exactly what escaping regular expression metacharacters does. Be careful if you're strings are double quoted though, because then you may need to escape your backslashes. It gets hairy quick because the string can get parsed multiple times and you have to think your way through that.

Okay, but to solve your problem it looks like you might just need a clever regexp, although I'm not sure. If you can describe succinctly what you changes to the URLs you want to make in general I think we should be able to help you with a more specific solution.

-jiblet

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 12-23-2001 00:41

jiblet, I know about the headache :-) I get it as well, it was a while since I wrote the code.
I don't have access to the notes server right now, but I'll dig up some example urls and a clearer explanation of what I want to do.
Thanx, Dan


-{ a vibration is a movement that doesn't know which way to go }-

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 12-26-2001 19:58

Sorry I didn't read your response yet, I don't have Internet at home anymore. Anyway, yeah, post some examples that illustrate what the range of possible URL transformations will be and we can no doubt post some regexps that at least simplify your code significantly.

-jiblet

« BackwardsOnwards »

Show Forum Drop Down Menu