Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Parseing text into catagories

    I have 1000 of these kind of data,

    Alpha Psi Beta
    Type of Organization: Honor
    President: xxxxxxxxxxxxx
    Advisor: xxxxxxxxxxxxxxxxxxxxxxx
    Requirements for Membership: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    Meeting Information: Every other Tuesday at 5:00PM in ######
    Amount of Dues: $30 one time National fee; $5 semester fee
    Description of Organization: Alpha Psi Beta is an honor society which recognized college-level theatre. We run workshops, fundraisers, field trips, and events that revolve around theatre.
    Website: www.alphapsiomega.org



    I need to break these into varibles so that i can write into database, what kind of reg ex can i use, to get the whole text at one like type of organisation or meeting information that are long of a exact word.


    any help will be appreciated.Need to do this soon .

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Are each one of the 1000 a file?
    For example, the one you showed us is xyz.txt (a text .txt file)?
    And are they all stored in the same directory?

    ... and is the database you're transferring them to MySQL?

    .
    Last edited by mlseim; 10-24-2011 at 05:00 PM.

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    yes the are in the file for now but i need to create a textfield where epople will copy and paste these type of data and i have to separate them and write them to the database.

    I tried using space to delimit and explode and then search through the array with a comparestring and change compare string incase of match but it does not work properly as you have linefeed and long match. My ugly code looks like this this will just get a submitted textfield. and there is a comparestring functing. But i need to do this simpler probably using pregmatch or something.
    PHP Code:
    //$temp=array();
    $compareString="Organization:";
    $vcount=0;
    $Temp;
            if(isset(
    $_POST['Submitted'])){    
            
            
    $text_Received=$_POST['info'];
            
            
            
    $text=explode(" ",$text_Received);
                    for (
    $i=0;$i<count($text);$i++){
                        
                          if(
    $i+1==count($text)){
                                echo 
    "reached end";
                          }
                          else{
                        
                                if(
    $text[$i]!=$GLOBALS['compareString']){
                                    
    //echo " ".$text[$i];
                                    
    addTo($text[$i]+" ");
                                    
                                    echo 
    $GLOBALS['compareString'];
                                    
    //echo $text[$i];
                                
    }else if($text[$i]==$compareString){
                                    
    compstring($compareString);
                                    
    //echo $text[$i+2];
                                    
    $vcount++;
                                    
                                    
                                }
                            
                            
                            
                            
                            
                                
                          }
                    }
        
        
            
                    
            } 

    just need the field in array. Thank you so much for looking in.

  • #4
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Ya and the database that i am using is mysql, i have another php that can write into mydatabase and that is working for any variables that i send using post. Am stuck in separating these field I am very bad with regex.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Is every 'record' 9 lines in size, and do they all contain the same potential categories and in the same order? Any separation between the records?
    Aside from the first line, every other line follows the same format of Category : Data. You don't need to use a regex on here at all if the records are all consistent.

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Here's basically what you can do .... as proof of concept (I never tested it though).

    Save your paragraph as a text file .. call it "alpha_psi_beta.txt" ...
    Then, run this test script (call it "test.php") and see what it does ...
    PHP Code:
    <?php

    // This puts the file into an array ... each line is one array element.
    $data=file("alpha_psi_beta.txt");

    // Now loop through and explode each line:
    foreach($data as $line){

    // Let's first change the proper : character to something not normally used, like pipe |
    // This is important because you sometimes use : for time (eg.  5:00)
    // You know that each line has a : followed by a space ... so we'll look for those.
    $string=str_replace(": ","|",$line);

    // Now separate the string by the pipe |
    $parts=explode("|",$string);

    // Only pick the lines with 2 parts (because the first line doesn't have : in it).
    if($parts[1]){
    // You now have 2 parts ... let's show them.  At this point you would be adding the
    // 2nd part to your database ...
    echo "Part 1: ".$parts[0]." <br />";
    echo 
    "Part 2: ".$parts[1]." >br /><br />";
    }
    }

    ?>


    .

  • Users who have thanked mlseim for this post:

    cooxee (10-24-2011)

  • #7
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    ya nearly all data are consistent but some have addition website and contact information after the description so i want to have the last variable with all the text after the Description of organisation. And the text of requiremnts and meeting information can be long with two or more lines so i cannot separate them by just finding the line feed.

    This is the result i was trying to achieve
    [NAme] => Array
    (
    [0] => Alpha Psi Beta
    [1]=>Honor
    [2] => xxxxxxxxxxxxx
    [3] => xxxxxxxxxxxxxxxxxxxxxxx
    [4]=>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    [5]=> Every other Tuesday at 5:00PM in ######
    [6]=>$30 one time National fee; $5 semester fee
    [7]=> Alpha Psi Beta is an honor society which recognized college-level theatre. We run workshops, fundraisers, field trips, and events that revolve around theatre. Website: www.alphapsiomega.org
    )

  • #8
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    thank you mlseim, the stuff works great and serves the purpose.

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    An FYI ...
    If all of your paragraphs of data (or whatever you call them) are each
    saved as .txt files, you can have PHP scan a directory and automatically
    open each .txt file one at a time, process it, and then move on to the next one.

    If your paragraphs are clumped together in one file, you'll need to have a way to
    find the separation between them. If the first line always has some text without
    a colon : ... that might be the way to separate them.


  •  

    Posting Permissions

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