Jump to content

using DOMdocument or else to merge contents of different elements!


jmahdi

Recommended Posts

 

Hi there:

 

what i'm trying to do is i want to get the contents of heading and text_details and merge them together before adding them as one entry into database:

<div class="heading"><p>

     Second quote: </div><div class=text_details>
                     
<p>

     Satan's substitute for repentance is the man's rationalization of evil.
<p></b></div>

 

my code looks s/thing like this:

foreach( $dom->getElementsByTagName('div') as $div ) {
            
            foreach( $div->attributes as $attributes ) {
                if( strtolower($attributes->name) == 'class' ) {
                     if( strtolower($attributes->value) == 'heading' || strtolower($attributes->value) == 'text_details') {
                        $quote = $div->textContent;
                        $clean_quote  = mysql_real_escape_string($quote);
                         echo "the quote is: " . $clean_quote . "<br />"; 
                        mysql_query("INSERT INTO quotes (quote) VALUES ('$clean_quote')")or die(mysql_error());
                    } 
                }
            }
    }

 

when i do this obviously i get: Second quote of the day entered into a field by itself and Satan's substitute for repentance is the man's rationalization of evil. into another field...how to make them one!??

 

thanks in advance

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.