[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

How to add target=_blank to some links in a html string

Asked by ApOG in PHP Scripting Language

Tags: html php links target=_blank

I need some help here:

Suppose I have this string:

$string = <p>Some text <a href="http://www.mydomain.com/436.php">link to my domain</a> some other text <a href="http://www.otherdomain.com">link to other domain</a>.

I need a function that adds target=_blank to links outside my domain, so they open in new windows. But if the link contains "www.mydomain.com" they function should NOT add the target=_blank.

This will be used for a custom blog where posters add any links and the script saves the output into a DB. This function should change the target of the link if it goes outside "www.mydomain.com".

Thanks!
 
Related Solutions
Keywords: How to add target=_blank to some lin…
 
Loading Advertisement...
 
[+][-]11/05/09 01:29 PM, ID: 25754243Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 01:31 PM, ID: 25754273Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 01:32 PM, ID: 25754276Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 01:34 PM, ID: 25754297Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 01:37 PM, ID: 25754314Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 02:04 PM, ID: 25754560Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 06:02 PM, ID: 25756090Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 07:38 AM, ID: 25759999Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625