• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

PHP removing tags

Hello,

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.

<div>
<a href="Details.aspx?Tr=243029002959224&">
SO51&nbsp;2000&nbsp;2900&nbsp;2909&nbsp;622
</a>
</div>
<div>
<a href="Details.aspx?Tr=290000002072265&">
SO51&nbsp;2000&nbsp;0000&nbsp;2002&nbsp;125
</a>
</div>


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!
0
Caruso_eu
Asked:
Caruso_eu
1 Solution
 
EMB01Commented:
I am not very good at regex, but can try this:

$var = <<<HTML
<div>
<a href="Details.aspx?Tr=243029002959224&">
SO51 2000 2900 2909 622
</a>
</div>
<div>
<a href="Details.aspx?Tr=290000002072265&">
SO51 2000 0000 2002 125
</a>
</div>
HTML;

$a = preg_match_all('/<a href="Details.aspx.Tr=[0-9]{15}&">.*</a>/', $var, $b);

var_dump($b);

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now