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

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.