Jump to content

Stripping html tags.


Heppy

Recommended Posts

Hey, I'm doing a thing for work, and I need to strip out a <li> tag from a source,

 

The li tag looks like this:

 

<li class="g" id="mbbDD">CONTENT HERE WITH TAGS NEWLINES ETC</li>

Where the DD in ID is random Numbers so any numbers should do.

 

<li class="g c35">

                  <h3 class="r">

                    <a href="http://www.massagestockholm.net/" class="l"><em>Massage Stockholm</em></a>

                  </h3>

 

                  <div class="s">

                    <em>Massage Stockholm</em> - Hitta och boka alla typer av massage i Stockholm. Enbart Bokadirekt-anslutna mass�rer. Thaimassage, Taktilmassage, Shiatsumassage <b>...</b><br>

                    <span class="f"><cite>www.<b>massagestockholm</b>.net/</cite> - <span class="gl"><a href="http://webcache.googleusercontent.com/search?q=cache:YROKHhfXogcJ:www.massagestockholm.net/+massage+stockholm&cd=8&hl=sv&ct=clnk&gl=se&ie=UTF-8">Cachad</a></span></span>

                  </div>

 

                </li>

                <li class="g c35">

                  <h3 class="r">

                    <a href="http://www.massagestockholm.net/Bookings/Default.aspx?sru=42" class="l">MASSAGEN vid Centralbadet i Stockholm - <em>Massage Stockholm</em></a>

                  </h3>

                  <div class="s">

                    <em>Massage</em> i <em>Stockholm</em> City bredvid Centralbadet Drottninggatan, boka <em>massage</em> <b>...</b><br>

 

                    <span class="f"><cite>www.<b>massagestockholm</b>.net/Bookings/Default.aspx?sru...</cite> - <span class="gl"><a href="http://webcache.googleusercontent.com/search?q=cache:R8fK37N8IxAJ:www.massagestockholm.net/Bookings/Default.aspx%3Fsru%3D42+massage+stockholm&cd=9&hl=sv&ct=clnk&gl=se&ie=UTF-8">Cachad</a></span></span>

                  </div>

                </li>

                <li class="g" id="mbb10">

                  <h3 class="r">

                    <a href="http://www.massagestockholm.net/Bookings/Default.aspx?sru=551" class="l">Kroppia - <em>Massage Stockholm</em></a>

 

                  </h3>

                  <div class="s">

                    <em>Massage Stockholm</em>? Rehabilitering Stockholm? Vid St Eriksplan. V�lkommen <b>...</b><br>

                    <span class="f"><cite>www.<b>massagestockholm</b>.net/Bookings/Default.aspx?sru...</cite> - <span class="gl"><a href="http://webcache.googleusercontent.com/search?q=cache:a0T8UoaQt3IJ:www.massagestockholm.net/Bookings/Default.aspx%3Fsru%3D551+massage+stockholm&cd=10&hl=sv&ct=clnk&gl=se&ie=UTF-8">Cachad</a></span></span>

 

                  </div>

                  <div class="mbl bl">

                    <span class="ch c36" id="mbl10" onclick="google.x(this)"></span>

                    <div class="mbi">

                      <span class="ch c36" id="mbl10" onclick="google.x(this)"></span>

                    </div><span class="ch c36" id="mbl10" onclick="google.x(this)"><a href="#" onclick="return false" class="mblink">Visa fler resultat fr�n massagestockholm.net</a></span>

                  </div>

                  <div id="mbf10"></div>

 

                </li>

                <li class="g">

                  <h3 class="r">

                    <a href="http://www.sthlmphysique.se/" class="l"><em>Massage</em> i <em>Stockholm</em>, Vasastan - Sthlm Physique - �ven presentkort</a>

                  </h3>

                  <div class="s">

                    STHLM Physique - Erbjuder <em>massage</em> mitt i Vasastan, <em>Stockholm</em>, med certifierade terapeuter. Best�ll <em>massage</em> presentkort direkt p� hemsidan. V�lkommen!<br>

                    <span class="f"><cite>www.sthlmphysique.se/</cite> - <span class="gl"><a href="http://webcache.googleusercontent.com/search?q=cache:1E4rvRvU_t4J:www.sthlmphysique.se/+massage+stockholm&cd=11&hl=sv&ct=clnk&gl=se&ie=UTF-8">Cachad</a> - <a href="/search?hl=sv&ie=UTF-8&q=related:www.sthlmphysique.se/+massage+stockholm&tbo=1&sa=X&ei=eiq8TOvVDIKfOtHplIcN&ved=0CEsQHzAK">Liknande</a></span></span>

                  </div>

                </li>

 

                <li class="g">

                    adam

                </li>

                <li>abscfgef</li>

                <li>soh3278462378</li>

                <li>

                    <a href="test.php">test</a>

                </li>

                <li>

                   

                </li>

 

 

This is my "solution" i've come up with but it doesn't work as I'd like.

It removes the designated tag AND everything after =/...

 

Any ideas?

 

preg_replace('/<li class="g" id="mbb[\d]*">(.*|\s*)*<\/li>/', "", $content);

 

 

//Heppy.

 

Link to comment
Share on other sites

kk,

There's a list of <li> tags

Some of the <li> tags has class, some of it has CLASS AND ID

 

<li class="g"></li>

<li class="g"><li>

<li class="g" id="mbb50"></li>

<li class="g"></li>

<li class="g"></li>

 

I want to get all the <li> elements with ONLY a class, NOT an ID.

Link to comment
Share on other sites

<?php
$string = '
<li class="g c35">
<h3 class="r">
<a href="http://www.massagestockholm.net/" class="l"><em>Massage Stockholm</em></a>
</h3>

<div class="s">
<em>Massage Stockholm</em> - Hitta och boka alla typer av massage i Stockholm. Enbart Bokadirekt-anslutna mass�rer. Thaimassage, Taktilmassage, Shiatsumassage <b>...</b><br>
<span class="f"><cite>www.<b>massagestockholm</b>.net/</cite> - <span class="gl"><a href="http://webcache.googleusercontent.com/search?q=cache:YROKHhfXogcJ:www.massagestockholm.net/+massage+stockholm&cd=8&hl=sv&ct=clnk&gl=se&ie=UTF-8">Cachad</a></span></span>
</div>

</li>
<li class="g c35">
<h3 class="r">
<a href="http://www.massagestockholm.net/Bookings/Default.aspx?sru=42" class="l">MASSAGEN vid Centralbadet i Stockholm - <em>Massage Stockholm</em></a>
</h3>
<div class="s">
<em>Massage</em> i <em>Stockholm</em> City bredvid Centralbadet Drottninggatan, boka <em>massage</em> <b>...</b><br>

<span class="f"><cite>www.<b>massagestockholm</b>.net/Bookings/Default.aspx?sru...</cite> - <span class="gl"><a href="http://webcache.googleusercontent.com/search?q=cache:R8fK37N8IxAJ:www.massagestockholm.net/Bookings/Default.aspx%3Fsru%3D42+massage+stockholm&cd=9&hl=sv&ct=clnk&gl=se&ie=UTF-8">Cachad</a></span></span>
</div>
</li>
<li class="g" id="mbb10">
<h3 class="r">
<a href="http://www.massagestockholm.net/Bookings/Default.aspx?sru=551" class="l">Kroppia - <em>Massage Stockholm</em></a>

</h3>
<div class="s">
<em>Massage Stockholm</em>? Rehabilitering Stockholm? Vid St Eriksplan. V�lkommen <b>...</b><br>
<span class="f"><cite>www.<b>massagestockholm</b>.net/Bookings/Default.aspx?sru...</cite> - <span class="gl"><a href="http://webcache.googleusercontent.com/search?q=cache:a0T8UoaQt3IJ:www.massagestockholm.net/Bookings/Default.aspx%3Fsru%3D551+massage+stockholm&cd=10&hl=sv&ct=clnk&gl=se&ie=UTF-8">Cachad</a></span></span>

</div>
<div class="mbl bl">
<span class="ch c36" id="mbl10" onclick="google.x(this)"></span>
<div class="mbi">
<span class="ch c36" id="mbl10" onclick="google.x(this)"></span>
</div><span class="ch c36" id="mbl10" onclick="google.x(this)"><a href="#" onclick="return false" class="mblink">Visa fler resultat fr�n massagestockholm.net</a></span>
</div>
<div id="mbf10"></div>

</li>
<li class="g">
<h3 class="r">
<a href="http://www.sthlmphysique.se/" class="l"><em>Massage</em> i <em>Stockholm</em>, Vasastan - Sthlm Physique - �ven presentkort</a>
</h3>
<div class="s">
STHLM Physique - Erbjuder <em>massage</em> mitt i Vasastan, <em>Stockholm</em>, med certifierade terapeuter. Best�ll <em>massage</em> presentkort direkt p� hemsidan. V�lkommen!<br>
<span class="f"><cite>www.sthlmphysique.se/</cite> - <span class="gl"><a href="http://webcache.googleusercontent.com/search?q=cache:1E4rvRvU_t4J:www.sthlmphysique.se/+massage+stockholm&cd=11&hl=sv&ct=clnk&gl=se&ie=UTF-8">Cachad</a> - <a href="/search?hl=sv&ie=UTF-8&q=related:www.sthlmphysique.se/+massage+stockholm&tbo=1&sa=X&ei=eiq8TOvVDIKfOtHplIcN&ved=0CEsQHzAK">Liknande</a></span></span>
</div>
</li>

<li class="g">
adam
</li>
<li>abscfgef</li>
<li>soh3278462378</li>
<li>
<a href="test.php">test</a>
</li>
<li>

</li>';

preg_match_all("(<li class=\"g(.*)</li>)siU", $string, $matches);
$result = $matches[0];
$parts = array();
foreach($result as $li) {
    if(!strstr($li, 'id="')) {
        $parts[] = $li;
    }
}

foreach($parts as $li) {
    print $li;    
}
?>

Link to comment
Share on other sites

Remade the your script and use the filter version and modified it a bit and added the class="g" & id="mbb

 

And it worked like a charm, now I get the same result as your script instead I just do it one one line of code :)

 

Couldn't have done it without your regexp thou, as that was the part that made it work. :)

Link to comment
Share on other sites

Remade the your script and use the filter version and modified it a bit and added the class="g" & id="mbb

 

And it worked like a charm, now I get the same result as your script instead I just do it one one line of code :)

 

Couldn't have done it without your regexp thou, as that was the part that made it work. :)

 

oh yeah, used the preg_replace()  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.