Page 1 of 1

to add extra property to a hyperlink?

Posted: Mon Mar 22, 2010 11:20 am
by rajaseeth
Hi,
I want to identify hyperlink tags in a string and then add a property "target" to that hyperlink. for example i have <a href ="http://www.google.com">google.com</a>. i want to add a property "target" to the above hyperlink like <a href ="http://www.google.com" target="_new">google.com</a>. I am new to programming, so please help me out..

Thanks
Raja

Re: to add extra property to a hyperlink?

Posted: Mon Mar 22, 2010 8:39 pm
by JakeJ
well, when you construct your URL, just concatinate different strings.

$a = 'Hello';

$b = 'World';

$c = $a. ' '.$b;

Echo $c;

Result: Hello World

echo $b;
//output is Hello world

Re: to add extra property to a hyperlink?

Posted: Tue Mar 23, 2010 4:38 pm
by ridgerunner
Try this:

Code: Select all

$contents = preg_replace('/<a\b([^>]*)>/', '<a$1 target="_new">', $contents);
:)