PHP removing tags

Posted on 2012-08-16
Last Modified: 2012-08-19

i have following problem ... i am sure its a simple solution but because i am fairly new to PHP i need a bit of guidance.

I want to remove tags that start with :

"<a href="Details.aspx?Tr=243029002"  (see below)  with string replace or some sort of similar function.

<a href="Details.aspx?Tr=243029002959224&">
<a href="Details.aspx?Tr=290000002072265&">

When i tried with this:

if (stripos($line, '<a href="Details.aspx?') !== false) {
                  $line = '';

... i deleted the whole line including SO51&nbsp;2000&nbsp;2900&nbsp;2909&nbsp;622 which must remain...

Thank you for your help!
Question by:Caruso_eu
    1 Comment
    LVL 14

    Accepted Solution

    I am not very good at regex, but can try this:

    $var = <<<HTML
    <a href="Details.aspx?Tr=243029002959224&">
    SO51 2000 2900 2909 622
    <a href="Details.aspx?Tr=290000002072265&">
    SO51 2000 0000 2002 125
    $a = preg_match_all('/<a href="Details.aspx.Tr=[0-9]{15}&">.*</a>/', $var, $b);

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now