modifying link tags.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • elliott.linux@gmail.com

    modifying link tags.

    ok what i need to do is modify all the link tags in a string from <a
    href="blah.html "to <a href="clicktrou gh.php?uri=blah .htmlbut the
    problem is some of the tags have class so <a class="llama"
    href="blah.html "but i dont want to change all of the tags that
    contain "href" because that would mess with the css. the code i am
    using right now is
    <?
    $file = file_get_conten ts('http://kingcow.com/');
    $llama = preg_split('/<a(.)*href=\"/', $file, -1, PREG_SPLIT_NO_E MPTY);
    echo join("",$llama) ;
    ?>
    this works but the problem is it removes the <a......>.

    any help is grately appricated.

    //elliott

  • Janwillem Borleffs

    #2
    Re: modifying link tags.

    elliott.linux@g mail.com wrote:
    ok what i need to do is modify all the link tags in a string from <a
    href="blah.html "to <a href="clicktrou gh.php?uri=blah .htmlbut the
    problem is some of the tags have class so <a class="llama"
    href="blah.html "but i dont want to change all of the tags that
    contain "href" because that would mess with the css.
    >
    Would something as follows do what you want?

    preg_replace('/(?<=href=")([^"]+)/', 'clicktrough.ph p?uri=$1', $source);


    JW


    Comment

    Working...