Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

regular expression / php / analytics question

  • 13-12-2010 10:39am
    #1
    Registered Users 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 Posts: 648 ✭✭✭ChicoMendez


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

    whys that ?


  • Registered Users 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