PHP removing tags

Posted on 2012-08-16
Medium Priority
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

EMB01 earned 2000 total points
ID: 38300848
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


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …
Suggested Courses
Course of the Month16 days, 5 hours left to enroll

850 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