Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2011
    Location
    Melbourne
    Posts
    637
    Tokens
    1,376

    Default Removing jargon from span fields

    Hello.

    Basically I have a whole heap of documents that are filled with jargon like this:
    PHP Code:
    <span class="xdTextBox" hidefocus="1" title="" tabindex="0" xd:binding="my:Ingredient" xd:ctrlid="CTRL17" xd:xctname="PlainText" style="BORDER-RIGHT: #dcdcdc 1pt; BORDER-TOP: #dcdcdc 1pt; FONT-WEIGHT: normal; FONT-SIZE: x-small; BORDER-LEFT: #dcdcdc 1pt; WIDTH: 100%; COLOR: #000000; BORDER-BOTTOM: #dcdcdc 1pt; FONT-STYLE: normal; FONT-FAMILY: Verdana; HEIGHT: 20px; TEXT-DECORATION: none">100Wholemeal Flour</span
    and I want to get rid of everything except the part that says 100% Wholemeal Flour at the very end so I can run it on multiple files and then insert it into a DB (that's the easy part, getting the text is hard). There is a table of between 3 and 10 ingredients depending on the recipe and each row has 6 columns. The first 2 are important.

    Any help at all will be appreciated.

  2. #2
    Join Date
    Nov 2008
    Posts
    217
    Tokens
    1,822
    Habbo
    eLv

    Latest Awards:

    Default

    You tried strip_tags yet?

    http://uk.php.net/strip_tags






  3. #3
    Join Date
    Oct 2011
    Location
    Melbourne
    Posts
    637
    Tokens
    1,376

    Default

    Quote Originally Posted by eLv View Post
    You tried strip_tags yet?

    http://uk.php.net/strip_tags
    Yep. Didn't work. Makes the result turn out like this:
    Code:
    Multi Grain Dough Ingredients%KgKgKgKgBakers Flour751.5003.7507.50018.750Multi Grain Mix250.5001.2502.5006.250

    The 751.5003.7507.50018.750 is all meant to be seperate values i.e. (Multi Grain Mix 25 0.500 1.250 2.500 6.250)

  4. #4
    Join Date
    Nov 2008
    Posts
    217
    Tokens
    1,822
    Habbo
    eLv

    Latest Awards:

    Default

    Maybe showing one of the document would be helpful, letting us know what the conditions we need to use to extract the info.






  5. #5
    Join Date
    Oct 2011
    Location
    Melbourne
    Posts
    637
    Tokens
    1,376

    Default

    Quote Originally Posted by eLv View Post
    Maybe showing one of the document would be helpful, letting us know what the conditions we need to use to extract the info.
    Here is a document. It is a Microsoft Sharepoint page but I don't have that so I need to rip out the first and second column (ingredients and percentages).
    Edit: use this link http://pastebin.com/zKtU1xfV
    Last edited by Blinger; 10-03-2014 at 07:24 AM.

  6. #6
    Join Date
    Nov 2008
    Posts
    217
    Tokens
    1,822
    Habbo
    eLv

    Latest Awards:

    Default

    The html is in a mess, haha. This can be easily done with simplehtmldom though, if you never heard of it before: http://simplehtmldom.sourceforge.net/

    PHP Code:
    <?php

        
    require_once( 'simple_html_dom.php' ); // The dom class file
        
        
    $file file_get_html'linkto.html' ); // Get the html, this can be linked to a url too
        
        
    $ingre['title'] = $file->find'span[xd:binding=my:RecipeTitle]')->innertext// Find the title
        
        // The main ingredient was different from those subs, so use this to get them
        
    $ingre['mainIngre']['name'] = strip_tags$file->find'table[xd:ctrlid=CTRL21] tr[style] td')->innertext );
        
    $ingre['mainIngre']['perc'] = strip_tags$file->find'table[xd:ctrlid=CTRL21] tr[style] td')->next_sibling()->innertext ); 
        
        
    // Now get the sub ingredient and put them into arrays
        
    foreach( $file->find'table[xd:ctrlid=CTRL21] tr[style]' ) as $tr ) {
            
    $ingreName = ( @$tr->find'span[xd:binding=my:Ingredient]')->innertext ) ? : false;
            
    $ingrePerc = ( @$tr->find'span[xd:binding=myercentage]')->innertext ) ? : false;
            if( 
    $ingreName || $ingrePerc ) {
                
    $ingre['subIngre'][] = array(
                    
    "name" => $ingreName,
                    
    "perc" =>  $ingrePerc '%'
               
    &nbsp;
            }
        }
        
    ?>
    <pre>
    <?php
        print_r
    $ingre );
    ?>
    </pre>
    Just use the same conditions if you want to extract the rest of the details, view the source of the html file and play the codes from there.

    The fun of programming.






  7. #7
    Join Date
    Oct 2011
    Location
    Melbourne
    Posts
    637
    Tokens
    1,376

    Default

    Quote Originally Posted by eLv View Post
    The html is in a mess, haha. This can be easily done with simplehtmldom though, if you never heard of it before: http://simplehtmldom.sourceforge.net/

    PHP Code:
    <?php

        
    require_once( 'simple_html_dom.php' ); // The dom class file
        
        
    $file file_get_html'linkto.html' ); // Get the html, this can be linked to a url too
        
        
    $ingre['title'] = $file->find'span[xd:binding=my:RecipeTitle]')->innertext// Find the title
        
        // The main ingredient was different from those subs, so use this to get them
        
    $ingre['mainIngre']['name'] = strip_tags$file->find'table[xd:ctrlid=CTRL21] tr[style] td')->innertext );
        
    $ingre['mainIngre']['perc'] = strip_tags$file->find'table[xd:ctrlid=CTRL21] tr[style] td')->next_sibling()->innertext ); 
        
        
    // Now get the sub ingredient and put them into arrays
        
    foreach( $file->find'table[xd:ctrlid=CTRL21] tr[style]' ) as $tr ) {
            
    $ingreName = ( @$tr->find'span[xd:binding=my:Ingredient]')->innertext ) ? : false;
            
    $ingrePerc = ( @$tr->find'span[xd:binding=myercentage]')->innertext ) ? : false;
            if( 
    $ingreName || $ingrePerc ) {
                
    $ingre['subIngre'][] = array(
                    
    "name" => $ingreName,
                    
    "perc" =>  $ingrePerc '%'
               
    &nbsp;
            }
        }
        
    ?>
    <pre>
    <?php
        print_r
    $ingre );
    ?>
    </pre>
    Just use the same conditions if you want to extract the rest of the details, view the source of the html file and play the codes from there.

    The fun of programming.
    I know. So frustrating and it can only be viewed in internet explorer otherwise the bottom half mucks up. What have the developers done!? Gar!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •