Welcome Guest, Not a member yet? Register   Sign In
preg_replace / regex - add attributes to link question
#1

[eluser]BobbyB[/eluser]
Hi,
my urls(in a string) look like this:
Code:
<a href="http://bit.ly/ddGgAi" class="twitter_news_links" target="_blank">http://bit.ly/ddGgAi</a>
I am trying to change them all to:
Code:
<a href="http://bit.ly/ddGgAi" class="twitter_news_links tips" term="http://bit.ly/ddGgAi" target="_blank">http://bit.ly/ddGgAi</a>
So I need to add a class name and the "term" Attribute which is supposed to be the same as "href".
How would you do this?
I have been playing around with regex/preg_replace but couldn't come up with a solution.
Any help is appreciated.
#2

[eluser]danmontgomery[/eluser]
I would use jQuery, personally.

Code:
$('a.twitter_news_links')
    .addClass('tip')
    .attr('term', function() {
        return $(this).attr('href');
    });

Would work, I think (haven't tested).
#3

[eluser]BobbyB[/eluser]
Hi,
you are probably right.
Thanks for sharing.
For Mootools 1.2
Code:
var links_ = $$('a.twitter_news_links');
         links_.each(function(el){
            el.addClass('tips_news');
            el.set('term',el.get('href'));
                    
                      })
Would still be interesting to see a php based solution for this.
Thanks




Theme © iAndrew 2016 - Forum software by © MyBB