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
to add extra property to a hyperlink?
Moderator: General Moderators
Re: to add extra property to a hyperlink?
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
$a = 'Hello';
$b = 'World';
$c = $a. ' '.$b;
Echo $c;
Result: Hello World
echo $b;
//output is Hello world
- ridgerunner
- Forum Contributor
- Posts: 214
- Joined: Sun Jul 05, 2009 10:39 pm
- Location: SLC, UT
Re: to add extra property to a hyperlink?
Try this:

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