1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Replace values between strings

Discussion in 'PHP' started by IamNed, Mar 11, 2010.

  1. #1
    I have spent hours looking for a solution to this to no avail

    I want to turn a bunch of text like this:


    <a href=http://www.321energy.com/>321 Energy</a><br>
    <a href=http://calenergy.blogspot.com/>California Energy</a><br>
    <a href=http://commontragedies.wordpress.com/>Common Tragedies</a><br>
    <a href=http://earlywarn.blogspot.com/>Early Warning</a><br>

    into this:


    <a href=http://www.321energy.com/></a><br>
    <a href=http://calenergy.blogspot.com/></a><br>
    <a href=http://commontragedies.wordpress.com/></a><br>
    <a href=http://earlywarn.blogspot.com/></a><br>

    I want the values between the /> and </a> tags removed
    Seems simple but no online guide seemed to explain it
     
    IamNed, Mar 11, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi,

    Try:
    $string='<a href=http://www.321energy.com/>321 Energy</a><br>
    <a href=http://calenergy.blogspot.com/>California Energy</a><br>
    <a href=http://commontragedies.wordpress.com/>Common Tragedies</a><br>
    <a href=http://earlywarn.blogspot.com/>Early Warning</a><br>';
    echo preg_replace('#(\<a[^\>]+\>)(.*?)(\</a\>)#misux','$1$3',$string)."\n";
    
    PHP:
    Regards :)
     
    koko5, Mar 11, 2010 IP
  3. elize

    elize Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    it's a matter of using preg_replace with regular expressions (regex) as koko described above. haven't checked their code yet, but it looks right.
     
    elize, Mar 11, 2010 IP