Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

regular expression / php / analytics question

  • 13-12-2010 11:39AM
    #1
    Registered Users, Registered Users 2 Posts: 648 ✭✭✭


    Hi,
    I'll be sending out a newsletter and i want to track clicks through GA. my idea is that i will grab all the links from the NL body and send them to a redirect script (with the GA campaign,source variables appended)
    the reason that i will use this redirect script is becuase some of the links in the NL will be external sites.

    is then a way with regular expressions to grab all the links and link text from a text block :

    <a href="link"> linktext </a>


    so as i can go


    foreach($matchedlinks as $singlelink){
    echo $singlelink->link;
    echo $singlelink->linktext;

    }



    thanks


Comments

  • Registered Users, Registered Users 2 Posts: 143 ✭✭James G


    (note: haven't used php in a while)

    You should be able to grab the links and store them in an array using preg_match_all.
    For the regexp, something like /^<a href="(.+)">(.+)<\/a>$/ should work fine.


  • Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭Placebo


    how are you sending this newsletter ? i hope its not through a homebrew app


  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    Placebo wrote: »
    how are you sending this newsletter ? i hope its not through a homebrew app

    whys that ?


  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    hi there,

    does anyone know how i would extract the title value from the link also please ?

    what changes would i need to make to :

    $regexp = "/<a\s[^>]*href=(\"??)(http[^\" >]*?)\\1[^>]*>(.*)<\/a>/siU";


    Many thanks !


  • Closed Accounts Posts: 1,150 ✭✭✭Ross


    Might be better off using a library like Simple HTML DOM or PHP's DOM API.

    Looks like overkill, but could save you some headaches down the road.


  • Advertisement
Advertisement