Copyright © 2005-2008 Andrea Tincani

AndreaPHP | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Geo target function)Next Topic (send mail with PHP) New Topic New Poll Post Reply
AndreaPHP Forum : PHP General : replace _blank with _top using eregi_replace
Poster Message
admin
Level: Administrator


Registered: 04-04-2002
Posts: 35

icon replace _blank with _top using eregi_replace

hello frinds,

I need a code to replace all the links pointing to a specific site with target="_blank" with the same URL but with target="_top"

i.e.
I have a string with the post made my a user, all links related to external sites will open in a new window but the links related to the same site of the forum will need to open in the same window...
if we have "[...] <a href="http://www.andreavb.com/anypage.html" target="_blank"> [...]" we need to produce a string with _blank replaced with _top but only if the related link starts with "http://www.andreavb.com" all other links related to external sites will keep the _top option

how can I write a replace function to do this?

____________________________
AndreaVB

21-02-2006 at 09:49 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 35

icon Re: replace _blank with _top using eregi_replace

I've found it!


<?
$Pattern 
"<a href=\"http://www.andreavb.com([^\"]*)\" target=\"_blank\">";
$Replacement "<a href=\"http://www.andreavb.com\\1\" target=\"_top\">";
$Message eregi_replace($Pattern$Replacement,$Message);
?>




[Edited by admin on 21-02-2006 at 03:02 PM GMT]

____________________________
AndreaVB

21-02-2006 at 02:01 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaPHP Forum : PHP General : replace _blank with _top using eregi_replace
Previous Topic (Geo target function)Next Topic (send mail with PHP) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: AndreaVB

Copyright © 2005-2008 Andrea Tincani

Powered by: tForum tForum Edition b0.92p1
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team.